|
Understanding the Ping and Traceroute Commands
yUmi# sh start ! Written by yUmis(牛奶咖喱) a.k.a. 红头发 Description 欢迎转po,请保留作者信息 Homepage http://www.show-tym.com QQ 13030130 Jun.27th.2004 !
什么是ping? ping是Packet Internet Groper的缩写,这个命令是最常见的用于检测网络设备可访问性的方法.它使用Internet Control Message Protocol(ICMP)的echo信息可以来决定: 1.远程设备是否可用 2.与远程主机通信的来回旅程(round-trip)的延迟(delay) 3.包(packet)的丢失情况
ping是如何工作的? 首先,ping发送echo request packet到某个地址,然后等待应答(reply),当echo request到达目标地址以后,在一个有效的时间内(timeout之前)返回echo reply packet给源地址.这样即说明能够ping通 (Cisco的router的timeout值默认为2秒)
下面是一个在启用了debug ip packet detail命令之后使用ping命令的输出内容的例子.(注意该debug命令将占用router大量的CPU资源甚至可能导致网络负载过大直至崩溃,记得在使用完毕以后no debug all) Router1#debug ip packet detail IP packet debugging is on (detailed)
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/6/8 ms
Router1# Jan 20 15:54:47.487: IP: s=12.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sending Jan 20 15:54:47.491: ICMP type=8, code=0 这是12.0.0.1发送到10.0.0.2的ICMP包,type=8说明是echo(详见后面的类型示意图) Jan 20 15:54:47.523: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 100, rcvd 3 Jan 20 15:54:47.527: ICMP type=0, code=0 来自10.0.0.2的应答,type=0说明是echo reply(详见后面的类型示意图)
ICMP type & code示意图如下:
此主题相关图片如下:
 一些返回的符号的含义如下: 1.叹号(!)代表成功收到响应 2.句号(.)代表在等待应答的时候超时间 3.U代表目标不可达(destination unreachable)或接收到错误的PDU 4.Q代表source quench,说明目标地址过于繁忙 5.M代表不能分片(fragment) 6.问号(?)代表未知的包的类型 7.符号&代表包的生存期(lifetime)超出
为什么我不能ping通? 来看一个例子.如下图:
此主题相关图片如下:
 先看下4个router的配置,如下: Router1# ! ! interface Serial0 ip address 12.0.0.1 255.255.255.0 no fair-queue clockrate 64000 ! ! Router2# ! ! interface Serial0 ip address 23.0.0.2 255.255.255.0 no fair-queue clockrate 64000 ! interface Serial1 ip address 12.0.0.2 255.255.255.0 ! ! Router3# ! ! interface Serial0 ip address 34.0.0.3 255.255.255.0 no fair-queue ! interface Serial1 ip address 23.0.0.3 255.255.255.0 ! ! Router4# ! ! interface Serial0 ip address 34.0.0.4 255.255.255.0 no fair-queue clockrate 64000 ! !
我们来试试在Router1上ping Router4: 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) 5个句号说明了结果失败
接下来启用debug ip packet detail实时监测,看下到底发生了什么: Router1#debug ip packet
IP packet debugging is on
再来ping Router4: 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: Jan 20 16:00:25.603: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable. Jan 20 16:00:27.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable. Jan 20 16:00:29.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable. Jan 20 16:00:31.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable. Jan 20 16:00:33.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable. Success rate is 0 percent (0/5) 可以看到输出包含unroutable,说明包无法被路由,那是因为我们没启用任何路由协议
在Router1上配置一条路由: Router1#config t Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#ip route 0.0.0.0 0.0.0.0 Serial0
再次启用debug ip packet detail以后,ping Router4: 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) Jan 20 16:05:30.659: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending Jan 20 16:05:30.663: ICMP type=8, code=0 Jan 20 16:05:30.691: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3 Jan 20 16:05:30.695: ICMP type=3, code=1 Jan 20 16:05:30.699: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending Jan 20 16:05:30.703: ICMP type=8, code=0 Jan 20 16:05:32.699: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending Jan 20 16:05:32.703: ICMP type=8, code=0 Jan 20 16:05:32.731: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3 Jan 20 16:05:32.735: ICMP type=3, code=1 Jan 20 16:05:32.739: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending Jan 20 16:05:32.743: ICMP type=8, code=0
Router2上出了什么问题? Router2#debug ip packet detail IP packet debugging is on (detailed)
Router2# Jan 20 16:10:41.907: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutable Jan 20 16:10:41.911: ICMP type=8, code=0 Jan 20 16:10:41.915: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sending Jan 20 16:10:41.919: ICMP type=3, code=1 Jan 20 16:10:41.947: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutable Jan 20 16:10:41.951: ICMP type=8, code=0 Jan 20 16:10:43.943: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutable Jan 20 16:10:43.947: ICMP type=8, code=0 Jan 20 16:10:43.951: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sending Jan 20 16:10:43.955: ICMP type=3, code=1 Jan 20 16:10:43.983: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutable Jan 20 16:10:43.987: ICMP type=8, code=0 Jan 20 16:10:45.979: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutable Jan 20 16:10:45.983: ICMP type=8, code=0 Jan 20 16:10:45.987: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sending Jan 20 16:10:45.991: ICMP type=3, code=1 Router1把包正确的发给了Router2,但是笨蛋Router2却不知道如何访问Router4(34.0.0.4),它回送unreachable ICMP信息给Router1
well,在Router2和3上启用RIP吧: Router2#router rip Router2#network 12.0.0.0 Router2#network 23.0.0.0
Router3#router rip Router3#network 23.0.0.0 Router3#network 34.0.0.0
这下再来看能不能ping通: 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: Jan 20 16:16:13.367: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending. Jan 20 16:16:15.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending. Jan 20 16:16:17.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending. Jan 20 16:16:19.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending. Jan 20 16:16:21.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending. Success rate is 0 percent (0/5) shit!还是不行,没有得到任何应答,看下Router4上到底发生了什么: Router4#debug ip packet IP packet debugging is on
Router4# Jan 20 16:18:45.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3 Jan 20 16:18:45.911: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutable Jan 20 16:18:47.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3 Jan 20 16:18:47.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutable Jan 20 16:18:49.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3 Jan 20 16:18:49.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutable Jan 20 16:18:51.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3 Jan 20 16:18:51.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutable Jan 20 16:18:53.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3 Jan 20 16:18:53.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutable 原来是这样,Router4收到了来自Router1的包,但是这个笨蛋却不知道如何应答.好吧,我给你加条静态路由: Router4(config)#ip route 0.0.0.0 0.0.0.0 Serial0
应该没问题了吧?let me try: 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 Bingo!终于成功了嘎嘎
上面这个例子里,ping不成功,是由于4个傻瓜不知道如何路由packet.下面再来看一个例子:
此主题相关图片如下:
 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) damn!又不成功!之前配置了路由协议了,应该不会是4个傻瓜找不到路的原因.那么,我们来1步步的排错吧: 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/4/4 ms ping Router2成功了,是不是Router3的问题呢??看看就知道了: Router3#show ip interface brief Serial0 34.0.0.3 YES manual up & [1] [2] [3] 下一页
 |
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。
| 原始作者:佚名 |
录入时间:2006-10-12 |
| 信息来源:不详 |
投稿信箱:itqoo@126.com |
|
|
 |
|