将接口配置为被动接口会完全阻止它发送路由更新,但有时候需要在路由更新中只抑制某些特定路由不被发送或接收。
这种阻止可能会被需要用来执行某个基于一些外部因素(例如链路成本、管理权限,或者安全考虑)的路由策略。
在有些情况下,我们可能想要通过阻止接入路由器接收完整的(而且可能是非常大的)核心路由表来减少不必要的开销。
基于这些原因,现在假定不想让路由器R1从R2学到去往网络2.2.2.0的路由如图1所示。
图1 如果过滤2.2.2.0的路由条目?
这时,可以用“distribute-list”命令来选择路由器想要为之发送或接收更新信息的路由。
通过引用一个访问控制列表,“distribute-list”命令创建了一个路由过滤器。
路由过滤器是一组精确控制路由器在路由更新中发送或者接收哪些路由的规则。
该命令可用于所有的IP路由选择协议。
当应用于进入的路由更新时,配置一个路由过滤器的命令句法如下:
Router(config-router)#distribute—list access-list-number in [interface-name]
当应用于外出的路由更新时,该命令的句法就要复杂一些:
Router(config-router)#distribute--list access-list-number out
[interface-name | routing-process | as-number]
当在不同的路由选择协议之间交换路由时可调用“routing-process”和“as-number”选项,这将在“路由重发布”中介绍。
“distribute-list”命令可以全局性地在一个外出或进入方向的路由更新中过滤任何路由。
Cisco IOS允许每一个路由进程发布入方向和出方向的全局性控制列表,也可以为一个路由进程所涉及到的每个接口发布进入方向的和外出方向的控制列表。
可以用“show ip protocols”命令显示哪些路由过滤器被全局性地应用,哪些被应用于特定接口上。
和RIP一样,被动接口不能发送EIGRP Hello分组,这将阻止路由器与链路伙伴建立毗邻关系,在OSPF中同样如此。
下面,给出例子中用distribute-list过滤2.2.2.0条目的配置:
在没有应用distribute-list以前,R1可以学习到去往2.2.2.0/24、2.3.3.0/24的详细子网路由。
R1#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
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
C 192.168.12.0/24 is directly connected, Serial1/0
1.0.0.0/24 is subnetted, 2 subnets
C 1.2.2.0 is directly connected, Loopback1
C 1.1.1.0 is directly connected, Loopback0
2.0.0.0/24 is subnetted, 2 subnets
R 2.3.3.0 [120/1] via 192.168.12.2, 00:00:07, Serial1/0
R 2.2.2.0 [120/1] via 192.168.12.2, 00:00:16, Serial1/0
为了过滤去往2.2.2.0子网的路由,在R2上应用distribute-list 1。
R2(config)#access-list 1 permit 2.3.3.0 0.0.0.255
R2(config)#router rip
R2(config-router)#distribute-list 1 out s1/1
这样,R2就不会把关于2.2.2.0的子网路由发送给R1了。在R1上效果如下:
R1#clear ip route *
R1#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
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
C 192.168.12.0/24 is directly connected, Serial1/0
1.0.0.0/24 is subnetted, 2 subnets
C 1.2.2.0 is directly connected, Loopback1
C 1.1.1.0 is directly connected, Loopback0
2.0.0.0/24 is subnetted, 1 subnets
R 2.3.3.0 [120/1] via 192.168.12.2, 00:00:02, Serial1/0
可以看到,运用distribute—list,确实可以达到过滤路由条目的目的,这是其他功能或协议所不能比拟的。