基础命令学习目录首页html
原文连接:https://blog.csdn.net/gechong123/article/details/80609598linux
ping命令用来测试主机之间网络的连通性。执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息,于是得知该主机运做正常。windows
ping(选项)(参数)
-d:使用Socket的SO_DEBUG功能; -c<完成次数>:设置完成要求回应的次数; -f:极限检测; -i<间隔秒数>:指定收发信息的间隔时间; -I<网络界面>:使用指定的网络界面送出数据包; -l<前置载入>:设置在送出要求信息以前,先行发出的数据包; -n:只输出数值; -p<范本样式>:设置填满数据包的范本样式; -q:不显示指令执行过程,开头和结尾的相关信息除外; -r:忽略普通的Routing Table,直接将数据包送到远端主机上; -R:记录路由过程; -s<数据包大小>:设置数据包的大小; -t<存活数值>:设置存活数值TTL的大小; -v:详细显示指令的执行过程。
ping命令经过ICMP(Internet控制消息协议)工做;ping能够用来测试本机与目标主机是否联通、联通速度如何、稳定性如何。
1
2
3
4
|
Usage:
ping
[-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination
|
参数 | 详解 |
---|---|
-a | Audible ping. |
-A | 自适应ping,根据ping包往返时间肯定ping的速度; |
-b | 容许ping一个广播地址; |
-B | 不容许ping改变包头的源地址; |
-c count | ping指定次数后中止ping; |
-d | 使用Socket的SO_DEBUG功能; |
-F flow_label | 为ping回显请求分配一个20位的“flow label”,若是未设置,内核会为ping随机分配; |
-f | 极限检测,快速连续ping一台主机,ping的速度达到100次每秒; |
-i interval | 设定间隔几秒发送一个ping包,默认一秒ping一次; |
-I interface | 指定网卡接口、或指定的本机地址送出数据包; |
-l preload | 设置在送出要求信息以前,先行发出的数据包; |
-L | 抑制组播报文回送,只适用于ping的目标为一个组播地址 |
-n | 不要将ip地址转换成主机名; |
-p pattern | 指定填充ping数据包的十六进制内容,在诊断与数据有关的网络错误时这个选项就很是有用,如:“-p ff”; |
-q | 不显示任何传送封包的信息,只显示最后的结果 |
-Q tos | 设置Qos(Quality of Service),它是ICMP数据报相关位;能够是十进制或十六进制数,详见rfc1349和rfc2474文档; |
-R | 记录ping的路由过程(IPv4 only); 注意:因为IP头的限制,最多只能记录9个路由,其余会被忽略; |
-r | 忽略正常的路由表,直接将数据包送到远端主机上,一般是查看本机的网络接口是否有问题;若是主机不直接链接的网络上,则返回一个错误。 |
-S sndbuf | Set socket sndbuf. If not specified, it is selected to buffer not more than one packet. |
-s packetsize | 指定每次ping发送的数据字节数,默认为“56字节”+“28字节”的ICMP头,一共是84字节; 包头+内容不能大于65535,因此最大值为65507(linux:65507, windows:65500); |
-t ttl | 设置TTL(Time To Live)为指定的值。该字段指定IP包被路由器丢弃以前容许经过的最大网段数; |
-T timestamp_option | 设置IP timestamp选项,能够是下面的任何一个: 'tsonly' (only timestamps) 'tsandaddr' (timestamps and addresses) 'tsprespec host1 [host2 [host3]]' (timestamp prespecified hops). |
-M hint | 设置MTU(最大传输单元)分片策略。 可设置为: 'do':禁止分片,即便包被丢弃; 'want':当包过大时分片; 'dont':不设置分片标志(DF flag); |
-m mark | 设置mark; |
-v | 使ping处于verbose方式,它要ping命令除了打印ECHO-RESPONSE数据包以外,还打印其它全部返回的ICMP数据包; |
-U | Print full user-to-user latency (the old behaviour). Normally ping prints network round trip time, which can be different f.e. due to DNS failures. |
-W timeout | 以毫秒为单位设置ping的超时时间; |
-w deadline | deadline; |
1
2
3
4
5
6
7
8
9
10
11
|
[root@aiezu.com ~]
# ping -c 5 -i 0.6 qq.com
PING qq.com (14.17.32.211) 56(84) bytes of data.
64 bytes from 14.17.32.211: icmp_seq=1 ttl=54
time
=16.5 ms
64 bytes from 14.17.32.211: icmp_seq=2 ttl=54
time
=17.0 ms
64 bytes from 14.17.32.211: icmp_seq=3 ttl=54
time
=16.6 ms
64 bytes from 14.17.32.211: icmp_seq=4 ttl=54
time
=18.3 ms
64 bytes from 14.17.32.211: icmp_seq=5 ttl=54
time
=19.9 ms
--- qq.com
ping
statistics ---
5 packets transmitted, 5 received, 0% packet loss,
time
2405ms
rtt min
/avg/max/mdev
= 16.520
/17
.692
/19
.919
/1
.293 ms
|
1
2
3
4
5
6
|
[root@aiezu ~]
# ping -f -s 65507 10.0.0.52
PING 10.0.0.52 (10.0.0.52) 65507(65535) bytes of data.
.^
--- 10.0.0.52
ping
statistics ---
646 packets transmitted, 646 received, 0% packet loss,
time
1675ms
rtt min
/avg/max/mdev
= 1.202
/2
.406
/8
.253
/0
.507 ms, ipg
/ewma
2.598
/2
.318 ms
|
1
2
3
4
5
6
7
8
9
|
[root@aiezu.com ~]
# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=8 ttl=43
time
=32.3 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=43
time
=32.2 ms
64 bytes from 8.8.8.8: icmp_seq=12 ttl=43
time
=32.0 ms
^C
--- 8.8.8.8
ping
statistics ---
17 packets transmitted, 3 received, 82% packet loss,
time
16003ms
rtt min
/avg/max/mdev
= 32.038
/32
.208
/32
.362
/0
.246 ms
|
1
2
3
4
5
|
[root@aiezu.com ~]
# ping -c 3 9.9.9.9
PING 9.9.9.9 (9.9.9.9) 56(84) bytes of data.
--- 9.9.9.9
ping
statistics ---
3 packets transmitted, 0 received, 100% packet loss,
time
1999ms
|
1
|
ping: packet size too large: 70000
|
1
2
3
4
|
WARNING: packet size 65508 is too large. Maximum is 65507
PING 10.0.0.52 (10.0.0.52) 65508(65536) bytes of data.
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
|