linxu下的ping命令的主要功能就是确定网络状态,下面由秋天网 Qiutian.ZqNF.Com小编为大家整理了linux的ping命令的详细解释的相关知识,希望对大家有帮助!

一、linux中的ping命令的详细解释

1.命令格式:

ping [参数] [主机名或ip地址]

2.命令功能:

ping命令用于:确定网络和各外部主机的状态;跟踪和隔离硬件和软件问题;测 试、评估和管理网络。如果主机正在运行并连在网上,它就对回送信号进行响应。每个回送信号请求包含一个网际协议(ip)和 icmp 头,后面紧跟一 个 tim 结构,以及来填写这个信息包的足够的字节。缺省情况是连续发送回送信号请求直到接收到中断信号(ctrl-c)。

ping 命 令每秒发送一个数据报并且为每个接收到的响应打印一行输出。ping 命令计算信号往返时间和(信息)包丢失情况的统计信息,并且在完成之后显示一个简要 总结。ping 命令在程序超时或当接收到 sigint 信号时结束。host 参数或者是一个有效的主机名或者是因特网地址。

3.命令参数:

-d 使用socket的so_debug功能。

-f 极限检测。大量且快速地送网络封包给一台机器,看它的回应。

-n 只输出数值。

-q 不显示任何传送封包的信息,只显示最后的结果。

-r 忽略普通的routing table,直接将数据包送到远端主机上。通常是查看本机的网络接口是否有问题。

-r 记录路由过程。

-v 详细显示指令的执行过程。

-c 数目:在发送指定数目的包后停止。

-i 秒数:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次。

-i 网络界面:使用指定的网络界面送出数据包。

-l 前置载入:设置在送出要求信息之前,先行发出的数据包。

-p 范本样式:设置填满数据包的范本样式。

-s 字节数:指定发送的数据字节数,预设值是56,加上8字节的icmp头,一共是64icmp数据字节。

-t 存活数值:设置存活数值ttl的大小。

二、linux中的ping命令的详解实例

实例1:ping的通的情况

命令:

ping 192.168.120.205

输出:

java代码

[[email protected] ~]# ping 192.168.120.205

ping 192.168.120.205 (192.168.120.205) 56(84) bytes of data.

64 bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms

64 bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms

64 bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms

64 bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms

64 bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms

--- 192.168.120.205 ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4000ms

rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms

[[email protected] ~]#

说明:

实例2:ping不通的情况

命令:

ping 192.168.120.202

输出:

java代码

[[email protected] ~]# ping 192.168.120.202

ping 192.168.120.202 (192.168.120.202) 56(84) bytes of data.

from 192.168.120.204 icmp_seq=1 destination host unreachable

from 192.168.120.204 icmp_seq=2 destination host unreachable

from 192.168.120.204 icmp_seq=3 destination host unreachable

from 192.168.120.204 icmp_seq=4 destination host unreachable

from 192.168.120.204 icmp_seq=5 destination host unreachable

from 192.168.120.204 icmp_seq=6 destination host unreachable

--- 192.168.120.202 ping statistics ---

8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms

, pipe 4

[[email protected] ~]#

说明:

实例3:ping网关

命令:

ping -b 192.168.120.1

输出:

java代码

[[email protected] ~]# route

kernel ip routing table

destination gateway genmask flags metric ref use iface

192.168.120.0 * 255.255.255.0 u 0 0 0 eth0

192.168.0.0 192.168.120.1 255.255.0.0 ug 0 0 0 eth0

10.0.0.0 192.168.120.1 255.0.0.0 ug 0 0 0 eth0

default 192.168.120.240 0.0.0.0 ug 0 0 0 eth0

[[email protected] ~]# ping -b 192.168.120.1

ping 192.168.120.1 (192.168.120.1) 56(84) bytes of data.

64 bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms

64 bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms

64 bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms

64 bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms

64 bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms

--- 192.168.120.1 ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4000ms

rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms

说明:

实例4:ping指定次数

命令:

ping -c 10 192.168.120.206

输出:

java代码

[[email protected] ~]# ping -c 10 192.168.120.206

ping 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms

64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms

64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms

64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms

64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms

64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms

64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms

64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms

64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms

64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms

--- 192.168.120.206 ping statistics ---

10 packets transmitted, 10 received, 0% packet loss, time 9000ms

rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms

[[email protected] ~]#

说明:

实例5:时间间隔和次数限制的ping

命令:

ping -c 10 -i 0.5 192.168.120.206

输出:

java代码

[[email protected] ~]# ping -c 10 -i 0.5 192.168.120.206

ping 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms

64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms

64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms

64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms

64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms

64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms

64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms

64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms

64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms

64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms

--- 192.168.120.206 ping statistics ---

10 packets transmitted, 10 received, 0% packet loss, time 4499ms

rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms

[[email protected] ~]# ping -c 10 -i 0.01 192.168.120.206

ping 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms

64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms

64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms

64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms

64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms

64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms

64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms

64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms

64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms

64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms

--- 192.168.120.206 ping statistics ---

10 packets transmitted, 10 received, 0% packet loss, time 90ms

rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms

[[email protected] ~]#

三、linux中的ping命令知识扩展

怎样使用ping这命令来测试网络连通呢?

•连通问题是由许多原因引起的,如本地配置错误、远程主机协议失效等,当然还包括设备等造成的故障。首先我们讲一下使用ping命令的步骤。

•使用ping检查连通性有六个步骤:

•1.使用ifconfig观察本地网络设置是否正确;

•2.ping127.0.0.1,127.0.0.1回送地址ping回送地址是为了检查本地的tcp/ip协议有没有设置好;

•3.ping本机ip地址,这样是为了检查本机的ip地址是否设置有误;

•4.ping本网网关或本网ip地址,这样的是为了检查硬件设备是否有问题,也可以检查本机与本地网络连接是否正常;(在非局域网中这一步骤可以忽略)

•5.ping本地dns地址,这样做是为了检查dns是否能够将ip正确解析。

•6.ping远程ip地址,这主要是检查本网或本机与外部的连接是否正常。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐