黑洞路由:
一、實驗目的:
1.通過制造斷路來實現路由傳輸中的環路現象
2.通過正確應用黑洞路由可以消除環路
二、拓撲結構:

三、實驗步驟:
①配置R1,R2,R3,R4及loopback口
R1:
interface Ethernet0/0/0
ip address 13.1.1.1 255.255.255.0
#
interface LoopBack0
ip address 10.1.1.1 255.255.255.0
#
ip route-static 10.1.0.0 255.255.0.0 13.1.1.3
ip route-static 34.1.1.0 255.255.255.0 13.1.1.3
R2:
interface Ethernet0/0/0
ip address 23.1.1.2 255.255.255.0
#
interface LoopBack0
ip address 10.1.2.1 255.255.255.0
#
ip route-static 10.1.0.0 255.255.0.0 23.1.1.1
ip route-static 34.1.1.0 255.255.255.0 23.1.1.1
R3:
interface Ethernet0/0/1
ip address 34.1.1.3 255.255.255.0
#
interface GigabitEthernet0/0/0
ip address 23.1.1.3 255.255.255.0
#
ip route-static 0.0.0.0 0.0.0.0 34.1.1.4
ip route-static 10.1.0.0 255.255.255.0 34.1.1.4
ip route-static 10.1.1.0 255.255.255.0 13.1.1.1
ip route-static 10.1.2.0 255.255.255.0 23.1.1.2
R4:
interface Ethernet0/0/0
ip address 34.1.1.4 255.255.255.0
#
interface LoopBack0
ip address 10.1.0.1 255.255.0.0
#
ip route-static 10.1.1.0 255.255.255.0 34.1.1.3
ip route-static 10.1.2.0 255.255.255.0 34.1.1.3
ip route-static 13.1.1.0 255.255.255.0 34.1.1.3
ip route-static 23.1.1.0 255.255.255.0 34.1.1.3
②斷開R2和R3之間的連接線,用R4 路由跟蹤R2
[r3-GigabitEthernet0/0/0]shutdown
<r4>tracert -a 10.1.0.1 10.1.2.1
traceroute to 10.1.2.1(10.1.2.1), max hops: 30 ,packet length: 40,press CTRL_C
to break
1 34.1.1.3 30 ms 30 ms 50 ms
2 34.1.1.4 30 ms 20 ms 40 ms
3 34.1.1.3 50 ms 60 ms 80 ms
4 34.1.1.4 80 ms 60 ms 60 ms
5 34.1.1.3 100 ms 80 ms 90 ms
R3斷之前的路由表:

R3斷之后的路由器表:

R4路由表:

在R3的接口斷開之后,當R4上ping 10.1.2.1,R4上會根據第四條路由去R3,到R3后查詢第二條路由表之后是到R4的,如此循環往復就出現了環路
wireshark抓包結果:
tracert結果

ping的結果:

ping 5個包,但是wireshark抓包抓取了1280個包。
③構建靜態黑洞路由后結果:
[r3]ip route-static 10.1.0.0 16 NULL 0
<r4>tracert -a 10.1.0.1 10.1.2.1
traceroute to 10.1.2.1(10.1.2.1), max hops: 30 ,packet length: 40,press CTRL_C
to break
1 * * *
2 * * *
添加路由黑洞后wireshark抓包:
ping 5個包,抓包也只能抓5個包

但是要注意:黑洞路由相當於是出現故障情況下的備用路由,所以可以把該條靜態黑洞路由的優先級設置低一點(值大一點)
但是黑洞路由在配置時要注意,正常黑洞路由的掩碼要比R3上的這條[R3]ip route-static 10.1.2.0 255.255.255.0 23.1.1.2的路由的掩碼要長,因為根據路由器查看路由表的最長匹配原則,掩碼越長越優先匹配。但是有同學擔心一旦R2和R3的斷了的接口恢復了,發往10.1.0.0/16的報文再匹配黑洞路由,那么報文會被丟棄,其實不用擔心,因為黑洞路由的掩碼比R2上的網段的路由掩碼要短(直連路由,更優)。
