发新话题
打印

[网络转载] 生平第一篇技术文档---ping命令

生平第一篇技术文档---ping命令

1.什么是ping

PingPacket Internet Groper的英文缩写。它使用ICMPecho协议信息在互联网络上检查计算机间物理连接的连通性。
扩展:ICMP(因特网控制报文协议),工作在网络层。被IP用于提供控制和信息传递功能,是一个管理性协议。它的信息是被作为IP数据报来传送的。

echo
协议的结果可以有助于评估以下内容:
*主机路径的可靠性

*
路径的延迟

*
主机能否到达或是否正在运行

Ping的操作可以在用户或特权EXEC模式下执行。

Ping返回代码

代码


含义



收到一个ICMP回应应答


.


等待应答时网络服务超时


U


收到一条ICMP不可达信息


C


收到一条ICMP源抑制信息


&


收到一条ICMP超时信息




2Ping的工作流程


   首先说明的是,ping是一个双向过程,下面这个流程图只是将其中的一个方向大致的画了出来。在这个过程中还有数据的封装和解封装过程没有在图上表示。



由于ping是一个双向过程,所以在ping 失败的时候,许多人会认为数据包没有到达目的主机。但是,有时候也会是由于路由器等设备缺乏返回源方主机网络的路由并将数据包丢 弃!数据包被丢弃在返回源方的旅途中,并不是丢弃在它前往目的主机的过程中。


还有一个需要注意的是。当主机A发送数据包到不同网络的主机B 时,所使用的目的方硬件地址时默认网关的以太网接口。这里因为数据帧是不可以被直接发送到远方网络的,它只有先发送到本地网络上 ,而且去往远程网络的数据包必须要通过默认网关转发!

Ping工作流程图



3.实例分析


TOPO1

   
实验目的:了解当ping自身的ip地址时,ping包是如何发送和接受的
实验假想:既然是ping自己那只要在自身内部发包和收包即可,不需要通过别的终端。

RA配置
Router>en
Router#conf t
Router(config)#host RA
RA(config)#int s1/0
RA(config-if)#ip add 192.168.1.2 255.255.255.0
RA(config-if)#no shu
RA(config-if)#clock rate 64000

RB的配置:
Router>en
Router#conf t
Router(config)#host RB
RB(config)#int s1/0
RB(config-if)#ip add 192.168.1.1 255.255.255.0
RB(config-if)#no shu
RB(config-if)#end
RB#debug ip pack

RB#ping 192.168.1.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/99/188 ms
RB#
*Nov
3 12:59:15.519: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), routed via FIB

*Nov
3 12:59:15.523: IP: s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), len 100, sending

*Nov
3 12:59:15.703: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:15.703: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:15.707: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), routed via FIB

*Nov
3 12:59:15.711: IP: s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), len 100, sending

*Nov
3 12:59:15.823: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:15.827: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:15.831: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), routed via FIB

*Nov
3 12:59:15.831: IP: s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), len 100, sending

*Nov
3 12:59:15.919: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:15.919: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:15.923: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), routed via FIB

*Nov
3 12:59:15.927: IP: s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), len 100, sending

*Nov
3 12:59:15.967: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:15.967: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:15.971: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), routed via FIB

*Nov
3 12:59:15.975: IP: s=192.168.1.1 (local), d=192.168.1.2 (Serial1/0), len 100, sending

*Nov
3 12:59:16.015: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:16.015: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

RB#ping 192.168.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 96/200/360 ms
RB#
*Nov
3 12:59:20.991: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:20.995: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.127: IP: tableid=0, s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.127: IP: s=192.168.1.2 (Serial1/0), d=192.168.1.1 (Serial1/0), len 56, rcvd 3

*Nov
3 12:59:21.199: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.199: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.203: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.207: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.271: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.271: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.279: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.279: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.343: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.343: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.347: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.351: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.415: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.415: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.419: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.423: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.463: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.463: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.467: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.471: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.535: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.535: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.539: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.543: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.607: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.607: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.611: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.615: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.631: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.631: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.635: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.639: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.703: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.707: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3

*Nov
3 12:59:21.707: IP: tableid=0, s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.711: IP: s=192.168.1.1 (local), d=192.168.1.1 (Serial1/0), len 100, sending

*Nov
3 12:59:21.991: IP: tableid=0, s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), routed via RIB

*Nov
3 12:59:21.991: IP: s=192.168.1.1 (Serial1/0), d=192.168.1.1 (Serial1/0), len 100, rcvd 3


在这个实例中我们发现RB ping RA所用的时间比RB ping自己所用的时间几乎少了一半。为什么ping自己的时间会比ping对方的时间长呢?
我们通过debug信息可以发现,当RB ping自己时,并不是按照我们想象的那样在自己的内部ping,那是怎么回事呢?
假想:ping自身时,需要通过RA

这时我们如果将RAIP地址去掉,RB还能ping通自己吗?如果不行,就验证了我们的假想
RA(config)#int s1/0
RA(config-if)#no ip add
RB#show cdp nei
Capability Codes: R - Router, T - Trans
Bridge, B - Source
Route
Bridge


S - Switch, H - Host, I - IGMP, r - Repeater


Device ID
Local Intrfce
Holdtme
Capability
Platform
Port ID

RA
Ser 1/0
129
R
7206VXR
Ser 1/0

RB#ping 192.168.1.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:

*Nov
3 15:50:35.211: IP: tableid=0, s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), routed via RIB

*Nov
3 15:50:35.215: IP: s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), len 100, sending.

*Nov
3 15:50:37.211: IP: tableid=0, s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), routed via RIB

*Nov
3 15:50:37.211: IP: s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), len 100, sending.

*Nov
3 15:50:39.211: IP: tableid=0, s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), routed via RIB

*Nov
3 15:50:39.211: IP: s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), len 100, sending.

*Nov
3 15:50:41.211: IP: tableid=0, s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), routed via RIB

*Nov
3 15:50:41.211: IP: s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), len 100, sending.

*Nov
3 15:50:43.211: IP: tableid=0, s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), routed via RIB

*Nov
3 15:50:43.215: IP: s=192.168.1.2 (local), d=192.168.1.2 (Serial1/0), len 100, sending.

Success rate is 0 percent (0/5)

此时无法ping通,这样就验证了我们的假想,ping自己要从对方那里走!

TOPO2


实验目的:验证ping是一个双向过程
配置:(ip地址的配置省略)
RB(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.1
RB#ping 192.168.2.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.2, timeout is 2 seconds:

*Nov
3 16:30:41.147: IP: tableid=0, s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), routed via FIB

*Nov
3 16:30:41.151: IP: s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), len 100, sending.

*Nov
3 16:30:43.147: IP: tableid=0, s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), routed via FIB

*Nov
3 16:30:43.147: IP: s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), len 100, sending.

*Nov
3 16:30:45.147: IP: tableid=0, s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), routed via FIB

*Nov
3 16:30:45.147: IP: s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), len 100, sending.

*Nov
3 16:30:47.147: IP: tableid=0, s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), routed via FIB

*Nov
3 16:30:47.147: IP: s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), len 100, sending.

*Nov
3 16:30:49.147: IP: tableid=0, s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), routed via FIB

*Nov
3 16:30:49.147: IP: s=192.168.1.2 (local), d=192.168.2.2 (Serial1/0), len 100, sending.

Success rate is 0 percent (0/5)
Ping不通,但是debug信息表示数据包已经发送成功
RC
RC#
*Nov
3 16:30:01.219: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:01.219: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:01.223: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

*Nov
3 16:30:20.851: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:20.851: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:20.855: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

*Nov
3 16:30:22.771: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:22.771: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:22.775: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

*Nov
3 16:30:24.739: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:24.739: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:24.743: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

*Nov
3 16:30:26.803: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:26.803: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:26.807: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

*Nov
3 16:30:28.795: IP: tableid=0, s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), routed via RIB

*Nov
3 16:30:28.795: IP: s=192.168.1.2 (Serial1/1), d=192.168.2.2 (Serial1/1), len 100, rcvd 3

*Nov
3 16:30:28.799: IP: s=192.168.2.2 (local), d=192.168.1.2, len 100, unroutable

提示没有路由,则在RC上加上一下配置
RC(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
RB#ping 192.168.2.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 96/160/224 ms
通了!


这个实验告诉我们,当ping对方不通的时候不一定是自己的问题,也许是对方主机上没有路由,需要到对方主机上核实信息。





ping命令作为最常用的检测设备间物理连通性的测试工具,在日常工作中大家都经常用到。我通过这几天的学习,将我所理解的ping命令写下来供大家参考。有什么不足和错误的地方希望大家能告诉我。


参考文献:

ITAA
视频教程




《思科网络技术学院教程(第一、二学期)》(第三版)





CCNA学习指南》




Understanding the Ping Command
BY
:红头发


TOP

发新话题