【转】Ping 返回符号的含义,你知道几个?

在路由器的故障分析中,Ping 命令是一个常见而实用的网络管理工具,用这种工具可以测试端到端的连通性,即检查源端到目的端网络是否通畅。Ping 的原理很简单,就是从源端向目的端发出一定数量的网络包,然后从目的端返回这些包的响应,如果在一定的时间内源端收到响应,则程序返回从包发出到收到的时间间隔,根据时间间隔就可以统计网络的延迟。如果网络包的响应在一定时间间隔内没有收到,则程序认为包丢失,返回请求超时的结果。我们经常让 Ping 一次发一定数量的包,然后检查收到相应的包的数量,则可统计出端到端网络的丢包率,而丢包率是检验网络质量的重要参数。

在路由器上 Ping 返回符号的含义如下表所示:

符号 描述
! 收到一个响应。
. 在等待时,网络服务器超时。
U 目标无法到达,受到错误的 PDU 。
Q 源消失(目标设备太忙)。
M 数据无法分割。
? 包类型未知。
& 包的有效期过了。

在路由器上无法 Ping 通一个地址的原因有很多种,譬如线路故障,对方路由器的接口没有起来,路由器的路由表中没有该地址的路由信息等等都会造成网络无法 Ping 通。

接下来会通过一个例子来说明一些 Ping 返回符号的含义,以下是该例子的简明拓扑图:

          12.0.0.2        23.0.0.3        34.0.0.4
R1 ———————————— R2 ———————————— R3 ———————————— R4
12.0.0.1        23.0.0.2        34.0.0.4
20.0.0.1
Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

在 Router 1 上无法 Ping 通 Router 4 的接口,通过使用 DEBUG 命令来获得更多的信息,便于进一步的分析:

Router1#debug ip packet
IP packet debugging is on
Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds:
5d21h: IP: s=12.0.0.1 (local), d=34.0.0.4, Len 100, unroutable.
5d21h: IP: s=12.0.0.1 (local), d=34.0.0.4, Len 100, unroutable.
……
Success rate is 0 percent (0/5)

我们看到 “ unroutable ” 的消息,表明在 Router 1 的路由表中不存在该地址的路由信息,Router 1 不知道该地址向何处转发,现增加一条缺省路由到 Router 1 中:

Router1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#ip route 0.0.0.0 0.0.0.0 Serial0/0

然后,再在 Router 1 上使用 Ping :

Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds:
U.U.U
Success rate is 0 percent (0/5)
6d03h: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0/0), Len 100, sending
6d03h: ICMP type=8, code=0
6d03h: IP: s=12.0.0.2 (Serial0/0), d=12.0.0.1 (Serial0/0), Len 56, rcvd 3
6d03h: ICMP type=3, code=1
……

再看看在 Router 2 上收到了什么信息:

Router2#
21:56:04: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, Len 100, unroutable
21:56:04: ICMP type=8, code=0
21:56:04: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), Len 56, sending
21:56:04: ICMP type=3, code=1
……

从上面的信息可以看出 Router 1 已经能正确地发送包到 Router 2 ,但好象 Router 2 并不知道如何转发地址 34.0.0.4 ,所以 Router 2 发送了 “ unreachable ” 的消息给 Router 1 。因此分别给 Router 2 和 Router 3 加上动态路由协议 RIP :

Router2#
router rip
network 12.0.0.0
network 23.0.0.0
Router3#
router rip
network 23.0.0.0
network 34.0.0.0

然后,在 Router 1 上 Ping Router 4 的接口:

Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds:
5d21h: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0/0), Len 100, sending.
5d21h: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0/0), Len 100, sending.
……
Success rate is 0 percent (0/5)

现在情况看起来好点,Router 1 能发包到 Router 4 ,只是收不到任何从 Router 4 返回的信息。看来 Router 4 上也有问题:

Router4#
6d23h: IP: s=12.0.0.1 (Serial0/0), d=34.0.0.4 (Serial0/0), Len 100, rcvd 3
6d23h: IP: s=34.0.0.4 (local), d=12.0.0.1, Len 100, unroutable
……

Router 4 收到了 ICMP 的包,但由于没有到 12.0.0.1 的路由信息,因此无法响应 12.0.0.1 所发过来的包。在 Router 4 上增加一条缺省路由:

Router4(config)#ip route 0.0.0.0 0.0.0.0 Serial0/0

这样问题得到了解决:

Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 32/35/36 ms

Router 1 上增加了一个 LAN 的接口:

Router1(config)#interface e0/1
Router1(config-if)#ip address 20.0.0.1 255.255.255.0

结果 LAN 上的一台 PC 机能 Ping 通 Router 1 ,但却无法 Ping 通 Router 2 ,而在 Router 1 上却能 Ping 通 Router 2 。

Router1#Ping 12.0.0.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/7/9 ms
Router1#
5d23h: IP: s=12.0.0.1 (local), d=12.0.0.2 (Serial0/0), Len 100, sending
5d23h: IP: s=12.0.0.2 (Serial0/0), d=12.0.0.1 (Serial0/0), Len 100, rcvd 3

在路由器上使用普通 Ping 时,其源 IP 地址为路由器上 Ping 包所出去的接口 IP 地址,在路由器上能通过使用扩展的 Ping 命令来更改缺省的源 IP 地址。现在在 Router 1 上通过使用扩展的 Ping 命令来模拟从 LAN 上发包到 Router 2 :

Router1#Ping
Protocol [ip]:
Target IP address: 12.0.0.2
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Source address or interface: 20.0.0.1
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Sweep range of sizes [n]:
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds:
5d23h: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0/0), Len 100, sending.
……
Success rate is 0 percent (0/5)

从上面的信息看,当源 IP 地址为 20.0.0.1 的时候,Router 1 能发包到 Router 2 ,只是无法收到 Router 2 的响应包。解决的办法很简单,只要在 Router 2 上增加一条路由到 20.0.0.0 就可以了。Ping 成功的基本原则就是被 Ping 设备也必须知道如何发送回包到发起 Ping 的源地址。从 Router 1 能 Ping 通 Router 2 是因为默认下是把包出口的接口的 IP 地址作为源地址。但由于原先 Router 2 并不知道新的 LAN ,所以当源地址为新的 LAN 的时候,就不知道如何发送回包到新的 LAN 。

从以上两个实例中可以看出来,在 Debug 命令的帮助下,我们也能通过 Ping 命令来发现和解决网络中的一些比较复杂的故障,而并不只是把它简单的作为测试网络是否通的工具而已。特别是路由器中的扩展的 Ping 命令所具有的可以任意设定源 IP 地址的特性,在实际使用当中更是能给我们在判断网络故障等方面带来很多的方便。

 

转自:http://bbs.hh010.com/thread-11868-1-1.html

这篇文章对你有帮助吗?

相关文章

发表评论?

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据