拓扑图如下:

要求:最终 要求PC0发送的数据包经过1线路到达PC1,PC1发送的数据包经过经过2线路到达pc0

配置如下:

router1配置接口ip:

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host r1

r1(config)#int f0/0

r1(config-if)#ip  add 192.168.10.1 255.255.255.0

r1(config-if)#no shut

r1(config-if)#int f0/1

r1(config-if)#ip add 192.168.20.1 255.255.255.0

r1(config-if)#no shutdown

r1(config-if)#int f1/0

r1(config-if)#ip add 192.168.40.1 255.255.255.0

r1(config-if)#no shutdown

Router2 配置接口ip:

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#int f0/0

Router(config-if)#ip add 192.168.30.2 255.255.255.0

Router(config-if)#no shut

Router(config-if)#int f1/0

Router(config-if)#ip add 192.168.40.2 255.255.255.0

Router(config-if)#no shut

Router(config-if)#int f0/1

Router(config-if)#ip add 192.168.50.1 255.255.255.0

Router(config-if)#no shut

Router0 配置接口ip:

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#int f0/0

Router(config-if)#ip add 192.168.20.2 255.255.255.0

Router(config-if)#no shut

Router(config-if)#int f0/1

Router(config-if)#ip add 192.168.30.1 255.255.255.0

Router(config-if)#no shut

Router1 配置静态路由,如下:

r1(config)#ip route 192.168.50.0 255.255.255.0 f0/1

查看路由表,如下图:

r1#sh ip route

Codes: C - connected, S - static, I - IGRP, 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, E - EGP

       i - IS-IS, 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.10.0/24 is directly connected, FastEthernet0/0

C    192.168.20.0/24 is directly connected, FastEthernet0/1

C    192.168.40.0/24 is directly connected, FastEthernet1/0

S    192.168.50.0/24 is directly connected, FastEthernet0/1

Router0有两条直连路由,所以需要添加一条到达 192.168.50.0 的路由,特权模式,如下命令:

r0(config)#ip route 192.168.50.0 255.255.255.0 f0/1

查看路由表,如下:

r0#sh ip route

Codes: C - connected, S - static, I - IGRP, 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, E - EGP

       i - IS-IS, 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.20.0/24 is directly connected, FastEthernet0/0

C    192.168.30.0/24 is directly connected, FastEthernet0/1

S    192.168.50.0/24 is directly connected, FastEthernet0/1

Router2有三条直连路由,只需要添加一条到达192.168.10.0 的静态路由,出站口为f1/0命令如下:

r2(config)#ip route 192.168.10.0 255.255.255.0 f1/0

查看路由表:

r2#sh ip route

Codes: C - connected, S - static, I - IGRP, 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, E - EGP

       i - IS-IS, 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

S    192.168.10.0/24 is directly connected, FastEthernet1/0

C    192.168.30.0/24 is directly connected, FastEthernet0/0

C    192.168.40.0/24 is directly connected, FastEthernet1/0

C    192.168.50.0/24 is directly connected, FastEthernet0/1

客户端测试:pc0可以ping通pc1,如下图:

使用抓包工具,观察经过的路径,首先在路由器中把停止cdp协议的运行,全局配置模式,使用命令: (config)#no cdp run

如下图显示所经过路径: