UNDERSTANDING THE
PING
COMMAND
思科网络技术文档
作者 红头发 CCIE#15101
Pt.1 Introduction to the Ping Command
Ping Overview
生物论文
背景知识:什么是ping?
男高音音域ping是Packet Internet Groper的缩写,这个命令是用于检测网络设备可访问性的最常见的方法.它使用互联网信息控制协议(ICMP)的echo信息可以来决定:
1.远程设备是否可用.权志龙水原希子
2.与远程主机通信的来回行程(round-trip)的延迟(delay).
菊花的功效和作用
3.数据包的丢失情况.
ping是如何工作的?
首先,ping发送echo request数据包到某个地址,然后等待应答,当echo request到达目标设备以后,在一个有效的时间内(超时之前)返回echo reply数据包给源设备.这样即说明连通性正常(Cisco路由器默认的超时时间为2秒).
一些返回的符号的含义如下:
1.叹号(!):代表成功收到响应.
2.句号(.):代表在等待应答的时候超时.
3.U:代表目标不可达(destination unreachable)或接收到错误的协议数据单元(PDU).
4.Q:说明目标设备的处理过于繁忙.
5.M代表不能分片(fragment).
6.问号(?):代表未知的数据包类型.
7.&:代表数据包的生存期(lifetime)超出.
Pt.2 Why I Can’t Ping Successfully?
Ca 1
第一种无法ping通的实例:
R1#ping 34.0.0.4
Type escape quence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 conds:
.....
Success rate is 0 percent (0/5)
接下来打开调试命令实时监测,继续执行ping命令,看下到底发生了什么:
星星上的人R1#debug ip packet
IP packet debugging is on
R1#ping 34.0.0.4
Type escape quence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 conds:
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)
可以看出因为目标地址和源地址不在同一网段,并且没有启用路由协议,因此无法ping通.
现在在R1上配置一条路由:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip route 0.0.0.0 0.0.0.0 Serial0
同时在R2上打开调试命令,继续尝试ping命令:
R1#ping 34.0.0.4
Type escape quence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 conds:
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, nding 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, nding 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, nding 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, nding Jan 20 16:05:32.743: ICMP type=8, code=0
R2#
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, nding
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, nding
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, nding
Jan 20 16:10:45.991: ICMP type=3, code=1
R1正确的把数据包转发给R2,但是由于R2上没有到达目标网络的路由,因此它无法正确的转发数据包.
现在在R2和R3上面配置路由协议:
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router rip
R2(config-router)#network 12.0.0.0
R2(config-router)#network 23.0.0.0
R2(config-router)#no auto-summary
R3#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#router rip
R3(config-router)#network 23.0.0.0
R3(config-router)#network 34.0.0.0
R3(config-router)#no auto-summary
继续尝试ping命令:
R1#ping 34.0.0.4
Type escape quence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 conds:
Jan 20 16:16:13.367: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, nding. Jan 20 16:16:15.
363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, nding. Jan 20 16:16:17.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, nding. Jan 20 16:16:19.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, nding.
Jan 20 16:16:21.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, nding. Success rate is 0 percent (0/5)税前和税后的区别
虽然R1到R4的路由都没问题了,但是R4却不知道如何把应答正确的返回:
R4#
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
解决方法是在R4上配置到R1的路由:
R4#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R4(config)#ip route 0.0.0.0 0.0.0.0 Serial0
再次尝试ping命令,一切正常:
R1#ping 34.0.0.4
Type escape quence to abort.
Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 conds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 32/35/36 ms
Ca 2
第二种无法ping通的实例:
打开调试命令实时监测,继续执行ping命令,看下到底发生了什么:
R2#debug ip packet
珍惜时间名言警句
IP packet debugging is on
R2#ping 100.0.0.5