一、拓扑图:
 
二、配置各路由器的IP和协议,在R2R3上做重分发,保证全网链路连通性。
 
三、完成基本的配置后,我们现在再看一下R4的路由表:
R4#sh ip route
Codes: 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
 
Gateway of last resort is not set
 
     172.16.0.0/24 is subnetted, 1 subnets
C       172.16.1.0 is directly connected, Serial1/0
     10.0.0.0/30 is subnetted, 2 subnets
R       10.1.1.0 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R       10.1.1.4 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R    192.168.0.0/24 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R    192.168.1.0/24 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R    192.168.2.0/24 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R    192.168.3.0/24 [120/10] via 172.16.1.1, 00:00:14, Serial1/0
R4#
 
四、我们现在要进入正题,将按照拓扑表中的要求,把192.168.0.0/24 192.168.2.0/24两条路由使用路由标记来过滤。路由标记过滤的方法分两个步骤:
1、在服务器端路由器设定标记(也就是我们这个图中的R2当作服务器端)
2、在客户端路由器根据标记进行过滤(也就是我们这里的R3当作客户端)
五、那么我们在服务器端路由器R2上设定标记:
R2(config)#access-list 1 permit 192.168.0.0 0.0.0.255(设定ACL,为我们标记服务,R2上可不过滤)
R2(config)#access-list 1 permit 192.168.2.0 0.0.0.255
R2(config)#route-map filter_tag permit 10(许可名为filter_tagroute-map 序号为10的名称)
R2(config-route-map)#match ip add 1 (匹配ACL 1)
R2(config-route-map)#set tag 1 (设置一个tag ,分配标记为1)
R2(config-route-map)#exit
R2(config)#route-map filter_tag permit 20(切记一定要加这一条,不然的话,将会如下图所示。意思是其它的没打上标记的路由都无条件转发出去。20为我们定义的route-map的序列号)
R2(config-route-map)#router ospf 1
R2(config-router)#redistribute eigrp 10 subnets route-map filter_tag(重分发时调用route-map,同时filter_tag标记也嵌入进去了)
 
(R2上不加命令route-map filter_tag permit 20 配置完后R4的效果图示)
R4#sh ip route
Codes: 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
 
Gateway of last resort is not set
 
     172.16.0.0/24 is subnetted, 1 subnets
C       172.16.1.0 is directly connected, Serial1/0
     10.0.0.0/30 is subnetted, 1 subnets
R       10.1.1.4 [120/10] via 172.16.1.1, 00:00:02, Serial1/0
R    192.168.0.0/24 [120/10] via 172.16.1.1, 00:00:02, Serial1/0
R    192.168.2.0/24 [120/10] via 172.16.1.1, 00:00:02, Serial1/0
 
说明:在R2上加上route-map filter_tag permit 20 意思是其它没有打上标记的路由都无条件转发,这样我们就形成了一个除了192.168.0.0/24192.168.2.0/24两条路由过滤外,其它没标记的路由都转发。R3上也要加上一条这种命令,不然也不会转发没有打上标记的其它路由。
 
六、我们再来对客户端路由器R3进行设置过滤服务端路由器设定的标记:
R3(config)#route-map match_tag deny 10 (R3建立一个名为macth_tag route-map)
R3(config-route-map)#match tag 1  (用来匹配标记 1,达到拒绝打了标记tag 1的路由)
R2(config-route-map)#exit
R3(config-route-map)#route-map match_tag permit 20(也一定要加,不然不会转发其它没标记的路由)
R3(config-route-map)#router rip(因为方向是往右的,也就是把ospf 重分发进rip,所以是进入rip)
R3(config-router)#redistribute ospf 1 metric 10 route-map match_tag(重分发时匹配刚建立的标记)
七、配置完之后,我们再来看一下R4形成的效果:
R4#sh ip route
Codes: 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
 
Gateway of last resort is not set
 
     172.16.0.0/24 is subnetted, 1 subnets
C       172.16.1.0 is directly connected, Serial1/0
     10.0.0.0/30 is subnetted, 2 subnets
R       10.1.1.0 [120/10] via 172.16.1.1, 00:00:01, Serial1/0
R       10.1.1.4 [120/10] via 172.16.1.1, 00:00:01, Serial1/0
R    192.168.1.0/24 [120/10] via 172.16.1.1, 00:00:01, Serial1/0
R    192.168.3.0/24 [120/10] via 172.16.1.1, 00:00:01, Serial1/0
 
八、从R4的路由表中我们看到了192.168.0.0/24 192.168.2.0/24两条路由被过滤掉了,这种方法在大的网络中还是很好的,因为客户端不需要加很多的访问控制列表,它只需要匹配标记就行。要做的只是在服务器端设置要过滤的路由标记。总之:我们过滤路由,也就是为了更好的维护网络中的路由更新和快速收敛。哪种方法适合我们的工作需要,更简单,我们就用哪种方法。