拓扑如下:
先实现在路由器从R3 ping 1.1.1.1 source 23.1.1.3 通过R2到达R1,而后R1直接把包转发给R3
R1 上有静态路由 ip route 0.0.0.0 0.0.0.0 fa0/0
ip route 23.1.1.0 0.0.0. fa0/1
acl access-list 1 permit 192.168.1.0 0.0.0.255
access-list 2 permit 192.168.1.0 0.0.0.255
nat ip nat inside soure list 1 interface fa 0/0 overload
ip nat inside soure list 2 interface fa 0/1 overload
R3上静态路由 ip route 1.1.1.0 0.0.0.255 fa 0/1
这样配置好后
在R3上ping 1.1.1.1 source 23.1.1.3 会出现
数据包从R1 fa0/0收到数据包,从fa0/1接口发回数据包
*Mar 1 00:47:22.039: IP: tableid=0, s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), routed via RIB
*Mar 1 00:47:22.043: IP: s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), len 100, rcvd 3
*Mar 1 00:47:22.047: IP: tableid=0, s=1.1.1.1 (local), d=23.1.1.3 (FastEthernet0/1), routed via FIB
access-list 4 permit 1.1.1.1
route-map 3 permit 20
match ip address 4
set ip next-hop 1.1.1.2
在路由器上开启本地发出的包也经过策略路由
ip local policy route-map 4
再在R3 上ping 1.1.1.1 source 23.1.1.3 出现的结果是
*Mar 1 00:51:43.927: IP: tableid=0, s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), routed via RIB
*Mar 1 00:51:43.931: IP: s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), len 100, rcvd 3
*Mar 1 00:51:43.983: IP: tableid=0, s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), routed via RIB
*Mar 1 00:51:43.987: IP: s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), len 100, rcvd 3
*Mar 1 00:51:44.023: IP: tableid=0, s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), routed via RIB
*Mar 1 00:51:44.027: IP: s=23.1.1.3 (FastEthernet0/0), d=1.1.1.1 (FastEthernet0/0), len 100, rcvd 3
可以看出进入的数据包没有走静态路由,而是通过策略路由走 fa0/0接口