任务 6:分析静态路由和默认路由的冲突问题
步骤 1:在 R1 上增加 Loopback100 和 Loopback200,IP 分别为 192.168.100.1/24 和 192.168.200.1/24,模拟 R1 连接着骨干网络的多个网段
R1(config)#interface loopback 100 R1(config-if)#ip address 192.168.100.1 255.255.255.0 R1(config-if)#exit R1(config)#interface loopback 200 R1(config-if)#ip address 192.168.200.1 255.255.255.0 R1(config-if)#exit
步骤 2:在 R2 上配置一条默认路由,下一跳是 192.168.12.1(R1)
R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.1
步骤 3:检查 R2 的路由表,发现了多条静态路由和一条默认路由,说明静态路由和默认路由 可以共存于路由表
R2#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 192.168.12.1 to network 0.0.0.0 C 192.168.12.0/24 is directly connected, FastEthernet0/0.12 C 192.168.24.0/24 is directly connected, FastEthernet0/0.24 S 192.168.4.0/24 is directly connected, FastEthernet0/0.24 C 192.168.23.0/24 is directly connected, FastEthernet0/0.23 S 192.168.1.0/24 [1/0] via 192.168.12.1 S 192.168.3.0/24 is directly connected, FastEthernet0/0.23 S* 0.0.0.0/0 [1/0] via 192.168.12.1
步骤 4:在 R2 上,使用 ping 测试到 192.168.100.1 的通信,发现能通,为什么?路由表的 哪条条目能转发到192.168.100.1 的数据包?
R2#ping 192.168.100.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.100.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 28/33/48 ms
R2#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 192.168.12.1 to network 0.0.0.0 C 192.168.12.0/24 is directly connected, FastEthernet0/0.12 C 192.168.24.0/24 is directly connected, FastEthernet0/0.24 S 192.168.4.0/24 is directly connected, FastEthernet0/0.24 C 192.168.23.0/24 is directly connected, FastEthernet0/0.23 S 192.168.1.0/24 [1/0] via 192.168.12.1 S 192.168.3.0/24 is directly connected, FastEthernet0/0.23 S* 0.0.0.0/0 [1/0] via 192.168.12.1 默认路由匹配了 192.168.100.1!
步骤 5:如果 R2 有数据包要去 192.168.3.1,路由表中有哪些路由可以匹配? 路由表中有 192.168.3.0/24 和 0.0.0.0/0 都可以匹配 192.168.3.1
R2#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 192.168.12.1 to network 0.0.0.0 C 192.168.12.0/24 is directly connected, FastEthernet0/0.12 C 192.168.24.0/24 is directly connected, FastEthernet0/0.24 S 192.168.4.0/24 is directly connected, FastEthernet0/0.24 C 192.168.23.0/24 is directly connected, FastEthernet0/0.23 S 192.168.1.0/24 [1/0] via 192.168.12.1 S 192.168.3.0/24 is directly connected, FastEthernet0/0.23 S* 0.0.0.0/0 [1/0] via 192.168.12.1
步骤 6:使用 ping 测试,发现能 ping 通 192.168.3.1,接着用 tracroute 测试到 192.168.3.1 的路径, 发现下一跳是 192.168.23.3,说明路由走的是 R3。说明但数据包能同时匹配静态路由和默认路由时,它 会优先被静态路由转发(静态路由更精确)
R2#ping 192.168.3.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.3.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 24/32/40 ms
R2#traceroute 192.168.3.1 Type escape sequence to abort. Tracing the route to 192.168.3.1 1 192.168.23.3 24 msec