基于策略的路由(PBR)

关于PBR的set ip next-hop和set ip default next-hop

基于策略的路由(PBR)

拓扑很简单,在R13和R16有lo0:1.1.1.1, R14要访问1.1.1.1,咱们经过set ip next-hop和set ip default next-hop来控制其选路,看看他们区别在什么地方.本实验拓扑简单,仅为测试相关feature。网络

1 . 基本环境介绍
R14模拟一台终端设备地址为192.168.42。14,其网关地址为192.168.42.12(R12 -> e0/0),R12使用P2P方式与R13和R16相连
R14的默认配置以下:
interface Ethernet0/0
ip address 192.168.42.14 255.255.255.0
no ip route-cache
ip default-gateway 192.168.42.12app

R12默认配置:
interface Serial1/0
ip address 192.168.23.12 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 192.168.26.12 255.255.255.0
serial restart-delay 0
!
此时R12路由表没有到1.1.1.1的路由,后面就须要经过PBR测试其联通性和进行选路
R12#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application routeide

    • replicated route, % - next hop override

Gateway of last resort is not setoop

192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.23.0/24 is directly connected, Serial1/0
L 192.168.23.12/32 is directly connected, Serial1/0
192.168.26.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.26.0/24 is directly connected, Serial1/1
L 192.168.26.12/32 is directly connected, Serial1/1
192.168.42.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.42.0/24 is directly connected, Ethernet0/0
L 192.168.42.12/32 is directly connected, Ethernet0/0测试

R13配置:
interface Loopback0
ip address 1.1.1.1 255.255.255.255
interface Serial1/0
ip address 192.168.23.13 255.255.255.0
serial restart-delay 0
ip route 0.0.0.0 0.0.0.0 Serial1/0 (默认路由出局)rest

R16配置:
interface Serial1/0
ip address 192.168.26.16 255.255.255.0
serial restart-delay 0
interface Loopback0
ip address 1.1.1.1 255.255.255.255
ip route 0.0.0.0 0.0.0.0 Serial1/0 (默认路由出局)code

2 . 根据上述配置,R14是没法ping通1.1.1.1,由于在R12并无到达1.1.1.1的路由
R14#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
U.U.U
Success rate is 0 percent (0/5)blog

2.1 需求1 ,咱们要求R14可以ping通1.1.1.1,而且走的路径是R14->R12->R13,那么咱们经过PBR将R12达到1.1.1.1的下一跳设置为R13的s1/0(192.168.23.13)
配置以下:
第一步:匹配流量,简单起见,直接匹配全部流量,固然也能够根据需求,匹配特定流量
access-list 1 permit any
第二步:配置route-map,匹配access-list,并设置下一跳为192.168.23.13
route-map map01 permit 1
match ip address 1
set ip next-hop 192.168.23.13
route-map map01 permit 2(除了匹配的流量,咱们须要放行其余流量,而后不作任何设置便可,所以须要在添加一条permit, 这一点必须注意)
第三步:将route-map应用于R12的e0/0口,
interface Ethernet0/0
ip address 192.168.42.12 255.255.255.0
ip policy route-map map01
完成上述配置后,咱们测试一下连通性和路径走向,能ping通,而且走的是R13
R14#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 9/10/12 ms
R14#tra
R14#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
1 192.168.42.12 1 msec 0 msec 0 msec
2 192.168.23.13 10 msec * 10 msecip

2.2 需求2, 如今R12在没有到达1.1.1.1的路由表的状况下,咱们经过PBR完成的连通性,那,咱们若是配置一条静态路由到1.1.1.1,下一跳是R16 s1/0(192.168.26.16),那R14是否能够ping通1.1.1.1,而且路径会不会变呢?
l R12配置:
咱们在需求1的基础上添加一条静态路由
Ip route 1.1.1.1 255.255.255.255 192.168.26.16ci

测试:
R14#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
1 192.168.42.12 0 msec 2 msec 1 msec
2 192.168.23.13 11 msec 10 msec
根据咱们测试,仍是会选在PBR设置的next-hop
结论:若是咱们使用PBR,而且设置使用set ip next-hop命令,那么next-hop的优先级要高于任何路由表项
2.3 需求3,若是咱们想优选路径为R14->R12->R16,应该如何进行修改呢?那就须要使用set ip default next-hop 192.168.26.16,
修改R12配置:
route-map map01 permit 1
match ip address 1
set ip default next-hop 192.168.23.13
测试:
R14#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
1 192.168.42.12 1 msec 1 msec 0 msec
2 192.168.26.16 11 msec
10 msec
测试如咱们所预料,路径发生了改变
结论:若是咱们使用PBR,而且设置使用set ip default next-hop命令,那么会先查看路由表有无该路由,若是有就优选路由表,不然在选择next-hop

2.4 需求4,若是咱们把静态路由改为缺省路由,PBR仍是采用set ip default next-hop,那么路径是否还会走R14->R12->R16呢?
修改R12配置:
将静态路由删除,改成缺省路由
ip route 0.0.0.0 0.0.0.0 192.168.26.16

测试:
R14#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
1 192.168.42.12 1 msec 2 msec 2 msec
2 192.168.23.13 10 msec * 11 msec
咱们发现,路径又回到了R14->R12->R13,那是为何呢?
结论:set ip default next-hop仅会对明细路由生效,因此对于缺省路由来说,当数据包到达R12后,发现并无到达1.1.1.1的明细路由,所以仍是走next-hop。所以,咱们能够总结如下:

基于策略的路由(PBR)

总结:不管是在点到点的网络环境(本实验环境)仍是多路访问的环境,都会遵循上表的原则。所以咱们能够使用PBR做为路由选路的一种方式,能够比较灵活的进行路由的控制,这里咱们使用的是静态路由,使用动态路由,也能够经过PBR完成路径的自由切换,你们不妨能够测试一下。

相关文章
相关标签/搜索