启用策略路由:
开始配置route-map。使用route-map map-tag [permit | deny] [sequence-number]进入route-map的配置模式。 使用match语句定义感兴趣的流量,如果不定义则指全部流量。match length min max and/or match ip address {access-list-number | name}[...access-list-number | name] 使用set命令设置数据包行为。 set ip precedence [number | name] set ip next-hop ip-address [... ip-address] set interface interface-type interface-number [... type number] set ip default next-hop ip-address [... ip-address] set default interface interface-type interface-number [... type ...number] 这里要注意set ip next-hop与set ip default next-hop、set interface与set default interface这两对语句的区别,不含default的语句,是不查询路由表就转发数据包到下一跳IP或接口,而含有default的语句是先查询路由表,在找不到精确匹配的路由条目时,才转发数据包到default语句指定的下一跳IP或接口。 进入想应用策略路由的接口。interface xxx 应用所定义的策略。注意必须在定义好相关的route-map后才能在接口上使用该route-map,在接口启用route-map策略的命令为: ip policy route-map map-tag要求:
访问新浪网络1.1.1.1时,电信用户5.5.5.5走电信线,网通用户55.55.55.55走网通线。
电信线路坏掉时自动切换到网通线路,网通线路坏掉时自动切换到电信线路,做一个冗余备份。
只能在网吧的R3路由器上操作。
基本IP规划(略)
全在192.168.0.0内
启用RIP路由协议(略)
R3
r3#show ip route
Gateway of last resort is not set
R 192.168.12.0/24 [120/1] via 192.168.23.2, 00:00:16, Serial0/2
1.0.0.0/24 is subnetted, 1 subnets
R 1.1.1.0 [120/2] via 192.168.34.4, 00:00:11, Serial0/1
[120/2] via 192.168.23.2, 00:00:16, Serial0/2
R 192.168.14.0/24 [120/1] via 192.168.34.4, 00:00:11, Serial0/1
55.0.0.0/24 is subnetted, 1 subnets
R 55.55.55.0 [120/1] via 192.168.35.5, 00:00:14, Serial0/3
5.0.0.0/24 is subnetted, 1 subnets
R 5.5.5.0 [120/1] via 192.168.35.5, 00:00:14, Serial0/3
C 192.168.23.0/24 is directly connected, Serial0/2
C 192.168.34.0/24 is directly connected, Serial0/1
C 192.168.35.0/24 is directly connected, Serial0/3
可见去往1.1.1.1的是负载均衡
启用Route map
R3
r3(config)#access-list 5 permit 5.5.5.0 0.0.0.255
r3(config)#access-list 55 permit 55.55.55.0 0.0.0.255
r3(config)#route-map ABC permit 10 策略1
r3(config-route-map)#match ip address 5
r3(config-route-map)#set ip next-hop 192.168.23.2 定制下一条为R2
r3(config)#route-map ABC permit 20 策略2
r3(config-route-map)#match ip address 55
r3(config-route-map)#set ip next-hop 192.168.34.4 定制下一条为R4
r3(config)#route-map ABC permit 30 空map,留作放行动作
r3(config-route-map)#end
r3(config)#int s0/3 接口下调用route-map
r3(config-if)#ip policy route-map ABC
r3(config-if)#end
R5
r5#traceroute 1.1.1.1 sou 5.5.5.5
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 192.168.35.3 80 msec 92 msec 92 msec
2 192.168.23.2 36 msec 144 msec 136 msec
3 192.168.12.1 56 msec 184 msec *
r5#tr
r5#traceroute 1.1.1.1 sou 55.55.55.55
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 192.168.35.3 72 msec 92 msec 56 msec
2 192.168.34.4 20 msec 120 msec 100 msec
3 192.168.14.1 20 msec 144 msec *
可见5.5.5.5去往1.1.1.1走R2,55.55.55.55去往1.1.1.1走R4
断开R3的S0/2接口(模拟电信线路坏掉)
R3
r3(config)#int s0/2
r3(config-if)#shut
r3(config-if)#end
R5
r5#ping 1.1.1.1 sou 5.5.5.5
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 5.5.5.5
!!!!!
可见会自动做冗余备份线路。