路由控制-策略路由
构建拓扑图:
# Simple lab
autostart = false
[localhost]
[[7200]]
image = C:\Program Files\Dynamips\images\unzip-c7200-js-mz.123-20.bin
ram = 96
nvram = 96
disk0 = 64
disk1 = 64
npe = npe-400
cnfg = None
confreg = 0x2102
mmap = false
#idlepc = 0x60490168(3640)
#idlepc = 0x6068802c
exec_area = 16
[[ROUTER R1]]
model = 7200
f0/0 = SW1 1
[[ROUTER R2]]
model = 7200
f0/0 = SW1 2
[[ROUTER R3]]
model = 7200
f0/0 = SW1 3
s1/2 = FR1 3
[[ROUTER R4]]
model = 7200
s1/2 = FR1 4
s1/1 = R5 s1/0
[[ROUTER R5]]
model = 7200
s1/1 = R6 s1/0
[[ROUTER R6]]
model = 7200
s1/2 = FR1 6
[[ETHSW SW1]]
1 = access 1
2 = access 1
3 = access 1
[[FRSW FR1]]
3:304 = 4:403
3:306 = 6:603
4:406 = 6:604
先给出基本的配置:
Router>
Router>en
Router#conf t
Router(config)#host R1 R1(config)#no ip domain-lo
R1(config)#line con 0 R1(config-line)#logg syn R1(config-line)#exec-time 0 0
R1(config-line)#exit R1(config)#
R1(config)#no ip routing
R1(config)#int f0/0
R1(config-if)#ip add 192.168.1.10 255.255.255.0 R1(config-if)#no shut
R1(config-if)#exit
R1(config)#
Router>en
Router#conf t
Router(config)#host R2
R2(config)#no ip domain-lo
R2(config)#line con 0
R2(config-line)#logg syn
R2(config-line)#exec-time 0 0
R2(config-line)#exit
R2(config)#
R2(config)#no ip routing
R2(config)#
R2(config)#int f0/0
R2(config-if)#ip add 192.168.1.20 255.255.255.0 R2(config-if)#no shut
R2(config-if)#exit
R2(config)#
Router>en
Router#conf t
Router(config)#host R3
R3(config)#no ip domain-lo
R3(config)#line con 0
R3(config-line)#logg syn
R3(config-line)#exec-time 0 0
R3(config-line)#exit
R3(config)#
R3(config)#int f0/0
R3(config-if)#ip add 192.168.1.1 255.255.255.0 R3(config-if)#no shut
R3(config-if)#exit
R3(config)#
R3(config)#int s1/2
R3(config-if)#encapsulation frame-relay R3(config-if)#ip add 10.1.1.1 255.255.255.0 R3(config-if)#no frame-relay inverse-arp R3(config-if)#frame-relay map ip 10.1.1.2 304 broadcast
R3(config-if)#frame-relay map ip 10.1.1.3 306 broadcast
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#
Router>en
Router#conf t
Router(config)#host R4
R4(config)#no ip domain-lo
R4(config)#line con 0
R4(config-line)#logg syn
R4(config-line)#exec-time 0 0 R4(config-line)#exit
R4(config)#
R4(config)#int s1/2
R4(config-if)#encapsulation frame-relay R4(config-if)#ip add 10.1.1.2 255.255.255.0
R4(config-if)#no frame-relay inverse-arp R4(config-if)#frame-relay map ip 10.1.1.1 403 broadcast
R4(config-if)#frame-relay map ip 10.1.1.3 406 broadcast
R4(config-if)#no shut
R4(config-if)#exit
R4(config)#
R4(config)#int s1/1
R4(config-if)#ip add 172.16.1.1 255.255.255.0
R4(config-if)#clockrate 64000 R4(config-if)#no shut
R4(config-if)#exit
R4(config)#
Router>en
Router#conf t
Router(config)#host R5
R5(config)#no ip domain-lo
R5(config)#line con 0
R5(config-line)#logg syn
R5(config-line)#exec-time 0 0 R5(config-line)#exit
R5(config)#
R5(config)#int s1/0
R5(config-if)#ip add 172.16.1.2 255.255.255.0
R5(config-if)#clockrat 64000 R5(config-if)#no shut
R5(config-if)#exit
R5(config)#
R5(config)#int s1/1
R5(config-if)#ip add 172.16.2.1 255.255.255.0 R5(config-if)#clockrate 64000
R5(config-if)#no shut
R5(config-if)#exit
R5(config)#
R5(config)#int lo0
R5(config-if)#ip add 130.130.1.1 255.255.255.0 R5(config-if)#exit
R5(config)#
Router>en
Router#conf t
Router(config)#host R6
R6(config)#no ip domain-lo
R6(config)#line con 0
R6(config-line)#logg syn
R6(config-line)#exec-time 0 0
R6(config-line)#exit
R6(config)#
R6(config)#int s1/2
R6(config-if)#encapsulation frame-relay R6(config-if)#ip add 10.1.1.3 255.255.255.0 R6(config-if)#no frame-relay inverse-arp R6(config-if)#frame-relay map ip 10.1.1.1 603 broadcast
R6(config-if)#frame-relay map ip 10.1.1.2 604 broadcast
R6(config-if)#no shut
R6(config-if)#exit
R6(config)#
R6(config)#int s1/0
R6(config-if)#ip add 172.16.2.2 255.255.255.0 R6(config-if)#clockrate 64000
R6(config-if)#no shut
R6(config-if)#exit
R6(config)#
在R3/R4/R5/R6启用路由协议RIPv2,并同时关闭自动汇总:
R3(config)#router rip
R3(config-router)#version 2
R3(config-router)#no auto-summary R3(config-router)#netw 192.168.1.0 R3(config-router)#netw 10.0.0.0 R3(config-router)#exit
R4(config)#router rip
R4(config-router)#version 2
R4(config-router)#no auto-summary
R4(config-router)#netw 10.0.0.0
R4(config-router)#netw 172.16.0.0
R4(config-router)#exit
R5(config)#router rip
R5(config-router)#version 2
R5(config-router)#no auto-summary
R5(config-router)#netw 172.16.0.0
R5(config-router)#netw 130.130.0.0
R5(config-router)#exit
R6(config)#router rip
R6(config-router)#version 2
R6(config-router)#no auto-summary
R6(config-router)#netw 10.0.0.0
R6(config-router)#netw 172.16.0.0
R6(config-router)#exit
检查R3的路由
:
R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 N1 -
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
Gateway of last resort is not set
172.16.0.0/24 is subnetted, 2 subnets
R 172.16.1.0 [120/1] via 10.1.1.2, 00:00:03, Serial1/2 R 172.16.2.0 [120/1] via 10.1.1.3, 00:00:10, Serial1/2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial1/2
130.130.0.0/24 is subnetted, 1 subnets
R 130.130.1.0 [120/2] via 10.1.1.2, 00:00:03, Serial1/2
[120/2] via 10.1.1.3, 00:00:10, Serial1/2 C 192.168.1.0/24 is directly connected, FastEthernet0/0 R3#
为了具体观察R3的路由转发,关闭CEF:(数据包的三种转发方式要了解) R3(config)#no ip cef
然后查看R3到130.130.1.1的数据包转发路径:
R3#traceroute 130.130.1.1
Type escape sequence to abort. Tracing the route to 130.130.1.1
1 10.1.1.2 36 msec
10.1.1.3 40 msec
10.1.1.2 20 msec
2 172.16.2.1 16 msec
172.16.1.2 24 msec *
R3#(可见,R3正使用两条路径转发数据包)
现在在R3上作策略,按照拓扑图进行分流:
R3(config)#access-list 10 permit host 192.168.1.10
R3(config)#access-list 20 permit host 192.168.1.20
R3(config)#
R3(config)#route-map cisco permit 10 R3(config-route-map)#match ip address 10 R3(config-route-map)#set ip next-hop 10.1.1.2 //创建
R3(config-route-map)#exit
R3(config)#
R3(config)#route-map cisco permit 20 R3(config-route-map)#match ip address 20 R3(config-route-map)#set ip next-hop 10.1.1.3
R3(config-route-map)#exit
R3(config)#
R3(config)#route-map cisco permit 30 R3(config-route-map)#exit
R3(config)#int f0/0
R3(config-if)#ip policy route-map cisco //调用
R3(config-if)#exit
验证最后的结果:
R1#traceroute 130.130.1.1
Type escape sequence to abort. Tracing the route to 130.130.1.1
1 192.168.1.1 68 msec 28 msec 72 msec
2 10.1.1.2 68 msec 56 msec 20 msec
3 172.16.1.2 12 msec * 16 msec R1#
R2#traceroute 130.130.1.1
Type escape sequence to abort. Tracing the route to 130.130.1.1
1 192.168.1.1 20 msec 60 msec 28 msec
2 10.1.1.3 8 msec 72 msec 40 msec
3 172.16.2.1 40 msec * 72 msec R2#
结束。