使用路由映射的策略库路由不起作用

网络工程 思科 pbr
2022-02-07 10:57:37

我想做的就是这样。
如果 R1 的 F0/1 的流量进入除目标 202.100.30.248/29 之外的任何源,则下一跳应为 192.168.1.1 在此处输入图像描述

R3 和 R2 都指定了指向 R1 路由器的默认静态路由,因此我可以从路由器 R3 ping 192.168.1.1。

但是当我尝试从 R3 ping 200.100.30.252 时,我没有得到回复,事实上我想知道我的 PBR 是否正常工作并转发数据包。200.100.30.252 不在 R1 路由表中。没有路由协议运行。

这是我在 R1 上配置的

    route-map PBR, permit, sequence 10
          Match clauses:
            ip address (access-lists): 104 
          Set clauses:
            ip default next-hop 192.168.1.1

    Extended IP access list 104
        10 permit ip any 202.100.30.248 0.0.0.7 log-input

   interface FastEthernet0/1
   ip address 172.16.1.2 255.255.255.252
   ip policy route-map PBR

R1 配置

R1#sh running-config 
Building configuration...
Current configuration : 1295 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
no ip icmp rate-limit unreachable
!
!
ip cef
no ip domain lookup
!
ip tcp synwait-time 5
!
interface FastEthernet0/0
 ip address 192.168.1.2 255.255.255.252
 duplex auto
 speed auto
!
interface FastEthernet0/1
 ip address 172.16.1.2 255.255.255.252
 ip policy route-map PBR
 duplex auto
 speed auto
!
interface FastEthernet1/0
 no ip address
 shutdown
 duplex auto
 speed auto
!
interface FastEthernet1/1
 no ip address
 shutdown
 duplex auto
 speed auto
!
ip forward-protocol nd
!
no ip http server
!
!
access-list 104 permit ip any 202.100.30.248 0.0.0.7 log-input
no cdp log mismatch duplex
!
route-map PBR permit 10
 match ip address 104
 set ip default next-hop 192.168.1.1
!
control-plane
!
gatekeeper
 shutdown
!
!         
line con 0
 exec-timeout 0 0
 privilege level 15
 logging synchronous
 stopbits 1
line aux 0
 exec-timeout 0 0
 privilege level 15
 logging synchronous
 stopbits 1
line vty 0 4
 login
!
!
end

我分析了从 R3 到 R1 的数据包,它只显示 ARP 广播询问谁是 202.100.30.252,并且没有回复该 ARP。
可能是我犯了一个大错误,我正在学习这个,请纠正我的错误。如果您需要更多内容,请询问。

2个回答

你写了

R3 和 R2 都指定了指向 R1 路由器的默认静态路由...

你还写道:

我分析了从 R3 到 R1 的数据包,它只显示 ARP 广播询问谁是 202.100.30.252,并且没有回复该 ARP。

好的,那么为什么 R3 ARPing 为 202.100.30.252?它不应该只是将 ICMP 数据包发送到 R1 吗?嗯,那是因为你在 R3 上有这个:

ip route 0.0.0.0 0.0.0.0 FastEthernet0/0

这与以下内容不完全相同:

ip route 0.0.0.0 0.0.0.0 172.16.1.2

您可以查看详细信息,但长话短说,第一种形式取决于 R1 上的代理 ARP 行为。事情是这样的:R1没有到最终目的地 (202.100.30.248/29) 的 IP 路由;它只有一个 PBR 规则。因此,当 ARP 请求到达时,R1 保持沉默,因此 R3 不会向 R1 发送 ICMP 数据包。

恐怕 R2 上的接口 f1/0(IP 200.100.30.252/29)没有真正启动,从而导致问题。请再次检查。

并且请为所有静态默认路由使用下一跳 IP 地址

R1 上的配置看起来不错,因为我用它来重现以下情况,我可以从 R3 ping 两个 IP 200.100.30.251 和 200.100.30.252。

在此处输入图像描述

路由器配置:

R1:

R1#
interface FastEthernet0/0
 ip address 192.168.1.2 255.255.255.252
 duplex auto
 speed auto
!
interface FastEthernet0/1
 ip address 172.16.1.2 255.255.255.252
 ip policy route-map PBR
 duplex auto
 speed auto
!
access-list 104 permit ip any 202.100.30.248 0.0.0.7 log-input

route-map PBR permit 10
 match ip address 104
 set ip default next-hop 192.168.1.1


R1#show ip route | beg Gateway
Gateway of last resort is not set

     172.16.0.0/30 is subnetted, 1 subnets
C       172.16.1.0 is directly connected, FastEthernet0/1
     192.168.1.0/30 is subnetted, 1 subnets
C       192.168.1.0 is directly connected, FastEthernet0/0
R1#

R3:

interface FastEthernet0/1
 ip address 172.16.1.1 255.255.255.252
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 172.16.1.2

R2:

interface FastEthernet0/0
 ip address 192.168.1.1 255.255.255.252
 duplex auto
 speed auto
!
interface FastEthernet0/1
 ip address 202.100.30.252 255.255.255.248
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 192.168.1.2

R4:

interface FastEthernet0/1
 ip address 202.100.30.251 255.255.255.248
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 202.100.30.252

确认

在 R3 上,ping 到 200.100.30.251 和 200.100.30.252 是成功的:

R3#ping 202.100.30.252

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 202.100.30.252, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 120/128/148 ms
R3#ping 202.100.30.251

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 202.100.30.251, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 96/131/164 ms

在 R1 上,会生成日志消息:

R1#
%SEC-6-IPACCESSLOGDP: list 104 permitted icmp 172.16.1.1 (FastEthernet0/1 ) -> 202.100.30.252 (0/0), 10 packets                                                                       
%SEC-6-IPACCESSLOGDP: list 104 permitted icmp 172.16.1.1 (FastEthernet0/1 ) -> 202.100.30.251 (0/0), 20 packets

更新的答案:

  1. 当我们为静态路由使用 (outgoing-) exit-interface 时,R3 路由器“认为”它直接连接到目标网络(这里是 0.0.0.0/0,包括 200.100.30.248/29 中的 IP 200.100.30.252),因此,路由器在第一次 ping 后从该退出接口发送该目标 IP(src:172.16.1.1 和 des:200.100.30.252)的 ARP 请求。

    当 ARP 请求到达 R1 时,R1 不知道目标 IP 202.100.30.252。因此它不做任何事情。

    无法在 R3 上创建目标 202.100.30.252 的 ARP 条目,所有 ICMP 数据包在封装时都失败并且不会发送出去。

  2. 当我们为静态路由使用下一跳 IP 地址时,R3 路由器知道它必须将流量路由到 R1 的 IP 地址 172.16.1.2 并且它需要该 IP 地址的 ARP 条目。因此,路由器仅在第一次 ping 后从直接连接的接口发送该下一跳 IP(src:172.16.1.1 和 des:172.16.1.2)的 ARP 请求。

    当 ARP 请求到达 R1 时,R1 会回复,因为 IP 地址 172.16.1.2 在其直连接口上。

    在 R3 上创建下一跳 IP 地址 172.16.1.2 的 ARP 条目,发送第二个和其余的 ICMP 数据包。这些 ICMP 数据包根据 R1 上的 PBR 进行验证。