空接口(Null interface)通常用于对路由环路的防范。Eigrp就这样,通常在路由汇总之后创建一条到Null的路由。当一种路由协议创建了汇总之后,就意味着这个路由器会接收来自这个汇总的任意数据包。因为不是这个汇总里面所有的网段都是在使用当中的,万一默认路由也在这个路由器上启用了,就可能会有包循环的危险发生。

一个最常见需要添加到null接口路由的场景是你一个有大量客户接入的访问服务器。这时该访问服务器需要添加到这些主机的路由。为了节省网络上路由表的条目,其它路由器往往只有指向该访问服务器的路由汇总。在配置上,也必须在该访问服务器添加一条到null 接口同样的汇总路由。否则,路由环路将会在外部主机尝试访问一台在汇总里面不存在的网段内的主机时发生。这是因为访问服务器因没有找到到该主机的路由而把这个数据包按默认路由发送回去。

看下面的例子:

利用NULL0接口防止路由环路_环路

一个小型Internet服务提供商向customer提供了192.168.0.0/16的地址块。在这里,客户使用了其中的192.168.1.0/24和192.168.2.0/24这两个网段。ISP在ISP-R1上配置了一条到192.168.0.0/16(cust-R2)的静态路由.BB-R3是骨干ISP,它上面配置了一条到ISP-R1的默认路由并从ISP-R1上通过BGP协议得到了到192.168.0.0/16的路由信息。

由于在cust-R2上也配置了一条到ISP-R1的默认路由,现在cust-R2已经顺利能连通到Internet(BB-R3)了。然而当某个数据包发往192.168.0.0/16网段内一个不在使用中的网段内的主机时,由于cust-r2使用了到isp-r1的默认路由来应答,这个数据包将会在isp-r1和cust-r2之间震荡直至TTL值消耗完。这极为浪费路由器和链路资源。这些发往未在使用中的网段地址的数据包很可能来自DOS和IP地址段内存活主机的扫描等。

有关配置(省略)

注意:路由器上开启了相关的debug语句以便于跟踪数据包流向,尤其是debug ip packet 和 debug ip icmp。切忌在生产环境中启用这些debug语句除非你完全清楚其后果。

BB-R3# ping ip 192.168.20.1 repeat 1 Type escape sequence to abort. Sending 1, 100-byte ICMP Echos to 192.168.20.1, timeout is 2 seconds: *Oct  6 09:36:45.355: IP: tableid=0, s=10.3.3.3 (local), d=192.168.20.1 (Serial2/0), routed via FIB *Oct  6 09:36:45.355: IP: s=10.3.3.3 (local), d=192.168.20.1 (Serial2/0), len 100, sending. Success rate is 0 percent (0/1) BB-R3# *Oct  6 09:36:50.943: ICMP: time exceeded rcvd from 10.0.0.1

可以看到,BB-R3向192.168.0.0/16汇总内一个没在使用的网段里某个主机发送了一个ICMP请求,然后从ISP-R1获得了一个超时应答。

现在看ISP-R1上的debug信息:

18:50:22: IP: tableid=0, s=10.3.3.3 (Serial1/0), d=192.168.20.1 (Serial0/0), routed via RIB 18:50:22: IP: s=10.3.3.3 (Serial1/0), d=192.168.20.1 (Serial0/0), g=192.168.20.1, len 100, forward 18:50:22: IP: tableid=0, s=10.3.3.3 (Serial0/0), d=192.168.20.1 (Serial0/0), routed via RIB 18:50:22: IP: s=10.3.3.3 (Serial0/0), d=192.168.20.1 (Serial0/0), g=192.168.20.1, len 100, forward 18:50:22: IP: tableid=0, s=10.3.3.3 (Serial0/0), d=192.168.20.1 (Serial0/0), routed via RIB 18:50:22: IP: s=10.3.3.3 (Serial0/0), d=192.168.20.1 (Serial0/0), g=192.168.20.1, len 100, forward 18:50:22: IP: tableid=0, s=10.3.3.3 (Serial0/0), d=192.168.20.1 (Serial0/0), routed via RIB  

可以看到isp-r1查找路由表之后转发了来自bb-r3的icmp请求至serial0/0出口。然后这个数据包马上又被cust-r2转发回到了isp-r1的serial0/0接口,我们查看一下isp-r1上到192.168.20.1的路由信息:

ISP-R1# show ip route 192.168.20.1 Routing entry for 192.168.0.0/16, supernet   Known via "static", distance 1, metric 0 (connected)   Advertised by bgp 65501   Routing Descriptor Blocks:   * directly connected, via Serial0/0

Route metric is 0, traffic share count is 1

为什么cust-r2把这个数据包送回给了isp-r1呢?

看cust-r2的debug:

*Oct  6 09:41:43.495: IP: s=10.3.3.3 (Serial2/0), d=192.168.20.1 (Serial2/0), g=10.0.0.1, len 100, forward *Oct  6 09:41:43.515: IP: tableid=0, s=10.3.3.3 (Serial2/0), d=192.168.20.1 (Serial2/0), routed via RIB *Oct  6 09:41:43.515: IP: s=10.3.3.3 (Serial2/0), d=192.168.20.1 (Serial2/0), g=10.0.0.1, len 100, forward *Oct  6 09:41:43.555: IP: tableid=0, s=10.3.3.3 (Serial2/0), d=192.168.20.1 (Serial2/0), routed via RIB

我们看到cust-r2把这些数据包送回了isp-r1,因为cust-r2查找不到192.168.20.0的网段而使用了默认路由:

cust-R2# show ip route 192.168.20.1 longer-prefixes 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 10.0.0.1 to network 0.0.0.0

Cust-r2没有到192.168.20.1的路由因为cust-r2下并没有这个网络,所以到192.168.20.1的最好路由还是那条指向isp-r1的默认路由。

结果将是,这些数据包将在isp-r1和cust-r2间震荡直至ICMP包定义的TTL值用完。注意如果ICMP请求往一个在使用中的网络,无论这个IP地址有没有在使用,上面的结果将不会发生。例如上例的ICMP请求向cust-r2下的192.168.1.x的地址,将不会发生环路。

解决例子中的这个问题的办法是在cust-r2上配置一条到192.168.0.0/16的静态路由,它的出口将是null0接口。

 

cust-R2# conf t Enter configuration commands, one per line.  End with CNTL/Z. cust-R2(config)# ip route 192.168.0.0 255.255.0.0 Null0 cust-R2(config)# end cust-R2# *Oct  6 09:53:18.015: %SYS-5-CONFIG_I: Configured from console by console cust-R2# show ip route 192.168.20.1 Routing entry for 192.168.0.0/16, supernet   Known via "static", distance 1, metric 0 (connected)   Routing Descriptor Blocks:   * directly connected, via Null0       Route metric is 0, traffic share count is 1

这时我们从新在BB-R3上ping 192.168.20.1,cust-r2把icmp包发往null0接口,因null接口只会丢弃数据包,将触发一条unreachable的icmp信息。

 

注意:并不是所有的情况下添加到null0接口的静态路由都是合适的:

  • ISP-R1 只有192.168.1.0/24的汇总,而不是汇总192.168.0.0/16

  • Block 192.168.1.0/24 is connected to another router which dials into cust-R2 via ISDN(这里还不是很明白,所以先不译了)

  • A disconnection of the ISDN link occurs

 

第一篇博文,翻译的很不专业,大家拍砖

原文地址:http://www.cisco.com/en/US/tech/tk364/technologies_tech_note09186a00801c9a6e.shtml