内容来源于人民邮电出版社《Linux命令应用大词典》

讲述729个命令,1935个例子

学习Linux系统的参考书、案头书,遇到不懂的命令或命令选项一查即可

争取每天都发布内容


本文出自 “airfish2000” 博客,更多命令查看博客:

http://airfish2000.blog.51cto.com/10829608/1870128


ping命令

使用ping命令可以用来测试与目标计算机之间的连通性。执行ping命令会使用ICMP传输协议发出要求回应的信息,如果远程主机的网络功能没有问题,就会回应该信息,因而得知该主机是否运作正常。

命令语法:

ping [选项] [目标]

命令中各选项的含义如表所示。

                                   ping命令选项含义

选项

含义

-c <完成次数>

设置完成要求回应的次数

-i <间隔秒数>

在每个数据包发送之间等待的时间(秒数)。缺省值为在每个数据包发送之间等待1

-n

指定只输出数字。不去查寻主机地址的符号名

-s <数据包大小>

指定要发送的数据的字节数。默认值是56

-t <存活数值>

设置存活数值TTL的大小       

-b

允许执行ping广播地址

-v

显示详细输出信息

-q

安静输出

-r

绕过正常的路由表,直接发送到连接接口上的主机

-W <超时>

等待一个响应的时间,单位为秒

-w <截止日期>

指定超时,单位为秒

-B

不允许ping来改变探测器的源地址

-L

抑制组播数据包的回送。仅适用ping目标是一个多播地址

-I <接口地址>

设置源地址为指定接口的地址

-R

记录路由

 

:测试与网站www.sina.com的连通性。

[root@rhel~]# ping www.sina.com

PINGjupiter.sina.com.cn (202.108.33.60) 56(84) bytes of data.

64bytes from 202.108.33.60: icmp_seq=1 ttl=248 time=108 ms

64bytes from 202.108.33.60: icmp_seq=2 ttl=248 time=17.7 ms

64bytes from 202.108.33.60: icmp_seq=3 ttl=248 time=47.0 ms

64bytes from 202.108.33.60: icmp_seq=4 ttl=248 time=22.3 ms

64bytes from 202.108.33.60: icmp_seq=5 ttl=248 time=95.3 ms

........................(省略)

//Linux系统中用该命令会不间断地返回ICMP数据包,要停止测试按[Ctrl+c]

:测试与计算机192.168.0.200的连通性,每次发送的ICMP数据包大小为128字节。

[root@rhel~]# ping -s 128 192.168.0.200

PING192.168.0.200 (192.168.0.200) 128(156) bytes of data.

136bytes from 192.168.0.200: icmp_seq=1 ttl=64 time=0.446 ms

136bytes from 192.168.0.200: icmp_seq=2 ttl=64 time=0.278 ms

136bytes from 192.168.0.200: icmp_seq=3 ttl=64 time=0.287 ms

136bytes from 192.168.0.200: icmp_seq=4 ttl=64 time=0.279 ms

136bytes from 192.168.0.200: icmp_seq=5 ttl=64 time=0.286 ms

136bytes from 192.168.0.200: icmp_seq=6 ttl=64 time=0.320 ms

136bytes from 192.168.0.200: icmp_seq=7 ttl=64 time=0.281 ms

........................(省略)

:测试与计算机192.168.0.200的连通性,发送4ICMP数据包。

[root@rhel ~]# ping -c 4 192.168.0.200

PING 192.168.0.200 (192.168.0.200) 56(84) bytes of data.

64 bytes from 192.168.0.200: icmp_seq=1 ttl=64 time=0.357ms

64 bytes from 192.168.0.200: icmp_seq=2 ttl=64 time=0.287ms

64 bytes from 192.168.0.200: icmp_seq=3 ttl=64 time=0.290ms

64 bytes from 192.168.0.200: icmp_seq=4 ttl=64 time=0.290ms

 

--- 192.168.0.200 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time3038ms

rtt min/avg/max/mdev = 0.287/0.306/0.357/0.029 ms