策略路由
目录
路径控制
offset-list的作用
用于在入站或出站时增大通过EIGRP或RIP获悉的路由度量值
PBR策略路由(Policy-Based Routing)
PBR对数据的处理
PBR的配置
PBR的配置
场景1
场景2
场景3
场景4
路径控制
构建冗余网络架构,除了上述之外的问题还包括:
弹性特性:不仅支持主动切换,还能利用备用线路以达到负载均衡的目的
系统可靠性:包括从主线路过渡至备线路所需的时间延迟
动态优化机制:当主线路出现拥塞迹象时,系统会自动切换至备线路
通信效率提升:通过合理分配带宽资源,系统总体吞吐量得以优化
offset-list的作用
用于在入站或出站时增大通过EIGRP或RIP获悉的路由度量值
Router(config-router)#
Offset List 可以配置为 {access-list-number 或 name} 方向 {in 或 out} 后跟 offset 接 [接口类型 接口号]

R1:
!
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Loopback1
ip address 11.11.11.11 255.255.255.0
!
interface FastEthernet0/0
ip address 192.168.13.1 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
offset-list 1 out 1 FastEthernet0/0
network 1.0.0.0
network 11.0.0.0
network 192.168.13.0
no auto-summary
!
R2:
!
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Loopback1
ip address 11.11.11.11 255.255.255.0
!
interface FastEthernet0/0
ip address 192.168.23.2 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
offset-list 1 out 1 FastEthernet0/0
network 1.0.0.0
network 11.0.0.0
network 192.168.23.0
no auto-summary
!
R3:
!
interface FastEthernet0/0
ip address 192.168.13.3 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.23.3 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
network 192.168.13.0
network 192.168.23.0
no auto-summary
!
R3路由表
1.0.0.0/24 is subnetted, 1 subnets
R 1.1.1.0 [120/1] via 192.168.13.1, 00:00:09, FastEthernet0/0
C 192.168.13.0/24 is directly connected, FastEthernet0/0
C 192.168.23.0/24 is directly connected, FastEthernet0/1
11.0.0.0/24 is subnetted, 1 subnets
R 11.11.11.0 [120/1] via 192.168.23.2, 00:00:23, FastEthernet0/1
PBR策略路由(Policy-Based Routing)
·基于策略的路由展现出显著的优势,在其运行过程中展现出更高的灵活性。这种 routing 策略通过多路由器的负载均衡机制实现对数据流量的动态分配,并能根据不同需求如目标地址、协议类型等自动优化路径选择。其中一种常见的策略是通过衡量各线路总流量来进行报文转发的质量控制。
·这种 routing 策略主要负责将经过路由器的数据流量进行分流与过滤,并对感兴趣的数据流进行匹配。
PBR对数据的处理

PBR的配置
匹配数据包IP地址、前缀列表
Router(config)# 打开 route-map 配置项
Router(config-route-map)# 进入 route-map 配置模式, 匹配 IP 地址 {access-list-number|name} [...]
匹配数据包大小
Router(config-route-map)#match length min max
设定分组的下一跳IP(必须为直连IP)
set ip next-hop ip-address [...ip-address]
设定分组的出接口
set interface type number [...type number]
应用PBR(对进入接口的数据流量生效,本地始发的流量无效)
router(config-if)# ip policy route-map map-tag
应用PBR(针对本地始发的流量生效)
router(config)# ip local policy route-map map-tag
PBR的配置
场景1

主要配置:
R3:
access-list 1 permit 192.168.1.0 0.0.0.255
route-map test permit 10
match ip address 1
set ip next-hop 192.168.13.1 192.168.23.2
ip policy route-map test
当网络正常时,R4访问100走左边。
当左边链路down掉,R4访问100走右边。
场景2
基于上图R1和R3之间

在R1 S1/0口in方向定义deny any
R4#p 100.100.100.100 //在R4上面ping 100.100.100.100
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 100.100.100.100, timeout is 2 seconds:
UUUUU //出现丢包
Success rate is 0 percent (0/5)
R1(config)#no cdp run //关闭CDP
R4#p 100.100.100.100
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 100.100.100.100, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 40/81/104 ms
R4#traceroute 100.100.100.100
Type escape sequence to abort.
Tracing the route to 100.100.100.100
1 192.168.1.254 20 msec 20 msec 20 msec
2 192.168.23.2 32 msec 40 msec 28 msec //说明走的是右边
R3:
Serial1/0 192.168.13.3 YES manual up up //Protocol还是up状态
场景3
还是场景1的那张图
利用IP SLA
例:
R3(config)#ip sla monitor responder //启用IP SLA监视器响应程序
R3(config)#ip sla monitor 1 //创建monitor 1
R3(config-sla-monitor)#type echo protocol ipIcmpEcho 192.168.13.1 source-ipaddr 192.168.13.3 //往对面ping
R3(config-sla-monitor-echo)#frequency 10 //频率(秒)
R3(config)#ip sla monitor schedule 1 life forever start-time now //一直生效,立即启动
R3(config)#track 1 rtr 1 reachability //绑定到track对象1
R3(config)#ip sla monitor 2
R3(config-sla-monitor)#type echo protocol ipIcmpEcho 192.168.23.2 source-ipaddr 192.168.23.3
R3(config-sla-monitor-echo)#frequency 10
R3(config)#ip sla monitor schedule 2 life forever start-time now
R3(config)#track 2 rtr 2 reachability
R3(config)#access-list 1 permit any
R3(config)#route-map test permit 10
R3(config-route-map)#match ip address 1
R3(config-route-map)#set ip next-hop 192.168.13.1 10 track 1
R3(config-route-map)#set ip next-hop 192.168.23.2 20 track 2
R3(config)#int f0/0
R3(config-if)#ip policy route-map test
场景4

route-map配置递归吓一跳
R1:
!
interface Loopback0
ip address 100.100.100.100 255.255.255.255
!
interface Serial1/0
ip address 192.168.14.1 255.255.255.0
serial restart-delay 0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 Serial1/0
!
R2:
!
interface Serial1/0
ip address 192.168.24.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 192.168.25.2 255.255.255.0
serial restart-delay 0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 192.168.24.4
ip route 100.0.0.0 255.0.0.0 s1/1
!
R3:
!
interface Loopback0
ip address 100.100.100.100 255.255.255.255
!
interface Serial1/0
ip address 192.168.34.3 255.255.255.0
serial restart-delay 0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 Serial1/0
!
R4:
!
interface FastEthernet0/0
ip address 192.168.1.254 255.255.255.0
ip policy route-map test
duplex auto
speed auto
!
interface Serial1/0
ip address 192.168.14.4 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 192.168.24.4 255.255.255.0
serial restart-delay 0
!
interface Serial1/2
ip address 192.168.34.4 255.255.255.0
serial restart-delay 0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 Serial1/0
ip route 192.168.25.0 255.255.255.0 Serial1/1
!
access-list 1 permit any
no cdp log mismatch duplex
!
route-map test permit 10
match ip address 1
set ip next-hop 192.168.34.3
set ip next-hop recursive 192.168.25.5
!
R5:
!
interface Loopback0
ip address 100.100.100.100 255.255.255.255
!
interface Serial1/0
ip address 192.168.25.5 255.255.255.0
serial restart-delay 0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 Serial1/0
!
//正常情况下ping100走R3
//R3、R4之间链路down掉
PC1> trace 100.100.100.100
trace to 100.100.100.100, 8 hops max, press Ctrl+C to stop
1 192.168.1.254 10.147 ms 10.069 ms 10.583 ms
2 192.168.24.2 32.446 ms 21.488 ms 31.383 ms
3 *192.168.25.5 34.054 ms (ICMP type:3, code:3, Destination port unreachable) //可以看到走R5
10. //R5和R2之间链路down掉
PC1> trace 100.100.100.100
trace to 100.100.100.100, 8 hops max, press Ctrl+C to stop
1 192.168.1.254 9.280 ms 9.535 ms 11.115 ms
2 192.168.24.2 31.610 ms 30.427 ms 31.990 ms
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 **192.168.24.4 28.047 ms (ICMP type:3, code:1, Destination host unreachable)
//R2和R4之间链路down掉
PC1> trace 100.100.100.100
trace to 100.100.100.100, 8 hops max, press Ctrl+C to stop
1 192.168.1.254 3.490 ms 10.619 ms 10.160 ms
2 *192.168.14.1 20.937 ms (ICMP type:3, code:3, Destination port unreachable) //可以看到走R1
