本节主要是通过静态路由设置的实验帮助读者深入地体会路由的概念,并切实把握静态路由的设置、查看路由表、设置无类路由等常用的命令。
1.实验目的
通过本实验,读者可以把握以下技能:
设置静态路由
设置启用路由器的路由功能
查看路由表
ping和trace命令的使用
2.设备需求
3台Cisco路由器,其中1台具有2个以太网接口,其余2台至少具有1个以太网接口;
2台Hub,4条双绞线 (也可以用2条交叉网线直接把3台路由器连接起来)
1台终端服务器,如cisco 2509路由器,及用于反向Telnet的相应线缆;
1台带有超级终端程序的PC机,以及Console电缆及转接器。
3.拓扑结构及配置说明
本实验的拓扑结构如图4-2所示。
3台路由器分别命名为R1、R2和R3,所使用的接口和相应的IP地址分配如图4.2中的标注。图中的"/24"表示子网掩码为24位,即255.255.255.0。
实验中,应使用静态路由的设置。实现R2到R3在IP层的连通性,即要求从R2可以ping通R3,反之亦然。
4.实验配置及监测结果
首先,根据拓扑结构图的要求,正确配置各路由器的以太网接口。
接下来的实验记录是从接口的配置工作完成之后开始的,具体内容见配置清单4-1。
配置清单4-1配置和监测静态路由
第1段:测试基本的连通性
Term_Server#1
[Resuming connection I to R1 ...]
R1#ping 10.1.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.2, timeout is 2 seconds:
!!!!!
SUCcess rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
Ripping 172.16.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.3, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 4/4/4 ms
R1#
(键入ctrl+shift+6,x,切换回终端服务器)
Term_Server#2
[Resuming connection 2 to R2 ... ]
R2#ping 172.16.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
.....
R2#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, 0 - 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
第2段:加入静态路由并测试连通性
R2#conft
Enter configuration commands, one per line. End with CNTL/Z,
R2(config)#ip route 172.16.1.0 255.255.255.0 10.1.1.1
R2(config)#end
R2#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, 0 - 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
172.16.0.0/24 is subnetted, 1 subnets
S 172.16.1.0[1/0]via 10.1.0.1
10.0.0.0/24 is subnetted,1subnets
C 10.1.1.0 is directly connected, EthernetO
R2#ping 172.16.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
HW
R2#ping 172.16.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos 10172.16.1.3, timeout is 2 seconds:
.....
success rate is 0 percent(0/5)
R2#
(键入ctrl+shift+6,x,切换回终端服务器)
Term_Server#3
[Resuming connection 3 to R3 ... ]
R3#conft
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#ip route 10.1.1.0 255.255.255.0 172.16.1.1
R3(config)#^Z
R3#ping 10.1.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/5/8 ms
R3#
R3#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP externa1, 0 -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, LI - 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
172.16.0.0/24 is subnetted, 1 subnets
C 172.16.1.0 is directly connected, EthernetO
10.0.0.0/24 is subnetted, 1 subnets
S 10.1.1.0[1/0]via 172.16.1.1
.
R3#
Term_Server#1
[Resuming connection I to R1 ... ]
R1#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, 0 - 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, LI - 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
172.16.0.0/24 is subnetted,1 subnets
C 172.16.1.0 is directly connected Ethernet0
10.0.0.0/24 is subnetted,1 subnets
C 10.1.1.0 is directly connected Ethernet0
R1#
(键入ctrl+shift+6, x切换回终端服务器)
Term_Server#2
[Resuming connection 2 to R2 ... ]
R2#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, 0 - 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, LI - 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 172.16.0.0/24 is subnetted, 1 subnets
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Ethernet0
R2#
(键入ctrl+shift+6, x切换回终端服器)
第3段:使用trace命令
Term_Server#3
[Resuming connection 3 to R3 ... ]
R3#trace 10.1.1.2
Type escape sequence to abort.
Tracing the route to 10.1.1.2
1 172.16.1.14msec 4 msec 4 msec
2 10.1.1.24msec 4 msec*
R3#
(键入ctrl+shift+6, x切换回终端服务器)
第4段:禁用IP路由功能
Term_Server#1
[Resuming connection I to R1 ... ]
R1#conft
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no ip routing
R1(config)#
R1#sh ip route
Default gateway is not set
Host Gateway Last Use Total Uses Interface
ICMP
R1#
(键入ctrl+shift+6,x切回换回终端服务器)
Term_Server#3
[Resuming connection 3 to R3 ... ]
R3#ping 172.16.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
.!!!!
Success rate. ia 80 percent (4/5), round-trip min/avg/max=4/5/8ms
R3#ping 10.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!
Successrateis 100 percent(5/5>,round-trip min/avg/max=4/4/4ms
R3#ping 10.1.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.2, timeout is 2 seconds:
Success rate is 0 percent(0/5)
R3#
(1)配置好各路由器的以太网接口地址后,在R1上用ping命令测试各网段内部的连通性。结果表明,R1到R2、R1到R3在IP层是正常连通的。
(2)接下来转到R2路由器上,在R2上ping172.16.1.1,即R1的E1接口地址,这是跨网段的ping,可以看到,没有ping通。
(3)在R2上执行show ip route命令查看其路由表,结果显示只有直接相连的网段10.1.1.0/24在其路由表内,标志为"C",即connected。
(4)在R2上加入1条静态路由:
ip route 172.16.1.0 255.255.255.0 10.1.1.1
这个语句的意思是:从本路由器出发,发往172.16.1.0 0 255.255.255.0网段的数据包,其下一跳点(Next Hop)的地址是10.1.1.1(即R1的E0接口地址)。
(5)在R2上配置好静态路由后,查看其路由表,结果显示刚刚加入的静态路由己经生效了。该路由表项前的"S"表示是静态(static)路由,中括号内的"1/10"表示这条路由的治理距离是1,度量值是0。这两个概念将在后续的实验中多次看到并加以说明。
(6)在R2上再次Ping172.16.1.1,成功;但是Ping与172.16.1.1处于同一个网段的172.16.1.3
(R3)则不成功。
上述结果的解释为:
在R2路由器上配置了到网段172.16.1.0/24的静态路由后,从R2发出的ICMP Echo包可以到达R1和R3路由器。R1路由器路由表内有到10.1.1.0/24网段的路由(直接相连),而R3、路由器则没有相应的路由表项。结果是R1可以发送ICMP Echo Reply包到10.1.1.2,而R3则不能发送ICMP Echo Reply包到1O.1.1.2,原因是没有到10.1.1.0/24网段的路由。
可能有一些喜欢深究问题的读者会问:你凭什么作如此解释,为什么不可以是从R1发出的ICMP包没有到达R3造成的ping不通R3?
我们可以用路由器上的监测结果来说明这个问题。
在R3上发出命令debug ip packet和debug ip icmp,来监测IP包和ICMP包的传输情况,得到的监测结果如下:
03:17:44:IP:s=10.1.1.2(Ethernet0),d=172.16.1.3(Ethernet0),len 100,rcvd3
03:17:44:ECMR echo reply sent,srcl72.16.1.3,dst 10.1.1.2
03:17:44:IP:s=172.16.1.3(local),d=10.1.12,len 100,unroutable
03:17:46:IP:s=10.1.1.2(Ethernet0),d=172.16.1.3(Ethernet0),len 100,rcvd3
03:17:46:ICMR echo reply sent,src 172.16.1.3,dst 10.1.1.2
03:17:46:IP:s=172.16.1.3(local),d=10.1.1.2,len 100,unroutable
以上监测结果表明:R3收到了来自R1的ICMP Echo包,源地址为10.1.1.2,目的地址为172.16.1.3;然后试图发送ICMP Echo reply包到10.1.1.2(R1),但是由于不可路由(即结果中的"unroutable")的原因,此IP包被丢弃,没有从R3路由器的任何接口上送出,从而造成R1不能接收到ICMP的应答包,导致Ping测试失败。
(7)使用trace命令可以显示IP包在传输的过程中的每一个跳点的IP地址,从而查看IP包所经过的整个路径。
(8)路由器的缺省配置是启动IP路由 即可以路由IP包。在第4段中,我们用no ip routing命令关闭了R1路由器的IP路由功能,然后发了3个ping指令,目的地址分别为172.16.1.1、10.1.1.1和10.1.1.2。可以看到前两个Ping是成功的,最后一个则失败。我们有必要记住这一结果,它表明了在禁用IP路由的情况下什么是可达,什么不可达。请注重在Ping指令发出之前用show ip route命令后的显示结果。