拓扑图:
配置参数:
R1

access-list 10 permit 192.168.5.0 0.0.0.255 //配置匹配的流量
route-map ospf permit 10 //创建一个路由图配置要匹配的流量

 match ip address 10  //关联要匹配的流量
 set metric 1 //设置匹配流量的度量值为1
route-map ospf permit 20 //接着用上面的路由图,配置序号为20,设置其它的流量

 set metric 2 //设置其它的流量的度量值为2
router ospf 1

redistribute rip subnets //OSPF里重发布RIP,让R4可以学习到
 network 192.168.3.0 0.0.0.255 area 0

router rip

 version 2

 redistribute ospf 1 route-map ospf //RIP里重发布OSPF,并应用上面配置好的路由图,达到 分流(两台设备[R1,R3]配置不同的度量值)和热备(动态路由可以动态感知网络拓扑的变化,动态的将度量值小的路由装进路由表)的效果 !!!
 network 192.168.1.0

 no auto-summary

 

R2:

access-list 20 permit 192.168.6.0 0.0.0.255

route-map ospf permit 10

 match ip address 20

 set metric 1

route-map ospf permit 20

 set metric 2

router ospf 1

redistribute rip subnets

 network 192.168.4.0 0.0.0.255 area 0

router rip

 version 2

 redistribute ospf 1 route-map ospf

 network 192.168.2.0

 no auto-summary
测试:
r5#sh ip int b
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.100.2   YES NVRAM  up                    up     
r5#traceroute 192.168.5.1

  1 192.168.100.1 1032 msec 20 msec 4 msec

  2 192.168.1.2 16 msec 8 msec 60 msec

  3 192.168.3.2 32 msec 12 msec *
r5#traceroute 192.168.6.1

  1 192.168.100.1 32 msec 16 msec 16 msec

  2 192.168.2.2 12 msec 28 msec 32 msec

  3 192.168.4.2 16 msec 32 msec *
r5#
可以看出要去192.168.5.0的网络走左边,去192.168.6.0的网络走右边!!!

 

配置成功后路由表是这样的:
R2:
R    192.168.4.0/24 [120/2] via 192.168.2.2, 00:00:17, Ethernet1/1

                    [120/2] via 192.168.1.2, 00:00:11, Ethernet1/0

     192.168.5.0/32 is subnetted, 1 subnets

R       192.168.5.1 [120/1] via 192.168.1.2, 00:00:11, Ethernet1/0

     192.168.6.0/32 is subnetted, 1 subnets

R       192.168.6.1 [120/1] via 192.168.2.2, 00:00:17, Ethernet1/1

C    192.168.1.0/24 is directly connected, Ethernet1/0

C    192.168.2.0/24 is directly connected, Ethernet1/1

C    192.168.100.0/24 is directly connected, FastEthernet0/0

R    192.168.3.0/24 [120/2] via 192.168.2.2, 00:00:17, Ethernet1/1

                    [120/2] via 192.168.1.2, 00:00:11, Ethernet1/0
可以看出,R2通过R1学习到192.168.5.0并且为1跳,通过R3学习到192.168.6.0并且为1跳。
现在来测试一下,将R1E0/0(连着R4的接口)down掉,看看会发现什么现象:
R1:

r1(config)#int e0/0

r1(config-if)#sh

r1(config-if)#shutdown
R2:

r2#sh ip rou

R    192.168.4.0/24 [120/2] via 192.168.2.2, 00:00:12, Ethernet1/1

     192.168.5.0/32 is subnetted, 1 subnets

R       192.168.5.1 [120/2] via 192.168.2.2, 00:00:12, Ethernet1/1

     192.168.6.0/32 is subnetted, 1 subnets

R       192.168.6.1 [120/1] via 192.168.2.2, 00:00:12, Ethernet1/1

C    192.168.1.0/24 is directly connected, Ethernet1/0

C    192.168.2.0/24 is directly connected, Ethernet1/1

C    192.168.100.0/24 is directly connected, FastEthernet0/0

R    192.168.3.0/24 [120/2] via 192.168.2.2, 00:00:12, Ethernet1/1

r2#
可以看出R2是通过R3学习到的192.168.5.0的路由的,它的跳数为2R5要去192.168.5.0的路由要走右边,因为左边的R1的上连端口down掉了。这样达到了热备的效果!!!

 

现在把R1E0/0再开启,看看会是什么效果:
R1:
r1(config)#int e0/0

r1(config-if)#no shutdown
R2:
r2#  SH IP ROU
R    192.168.4.0/24 [120/2] via 192.168.2.2, 00:00:05, Ethernet1/1
                    [120/2] via 192.168.1.2, 00:00:25, Ethernet1/0
     192.168.5.0/32 is subnetted, 1 subnets
R       192.168.5.1 [120/1] via 192.168.1.2, 00:00:25, Ethernet1/0

     192.168.6.0/32 is subnetted, 1 subnets
R       192.168.6.1 [120/1] via 192.168.2.2, 00:00:05, Ethernet1/1

C    192.168.1.0/24 is directly connected, Ethernet1/0
C    192.168.2.0/24 is directly connected, Ethernet1/1
C    192.168.100.0/24 is directly connected, FastEthernet0/0
R    192.168.3.0/24 [120/2] via 192.168.2.2, 00:00:05, Ethernet1/1
                    [120/2] via 192.168.1.2, 00:00:25, Ethernet1/0
r2#
可以看出,R2通过动态路由感知到网络拓扑的变化,动态地学习到了度量值优的路由,然后入进入路由表里!!!