-- TOC --
本文介绍iputils项目里著名的ping命令,主要介绍它的一些参数的用法。
-cN
,设置发送ping报文的个数,默认会一直发,直到Ctrl-C;
-iT
, 设置每个ping报文的间隔时间,默认是1秒,普通用户最小可以设置为0.2秒,小于这个值,需要root权限。
-q
,安静模式。个人感觉用上这个参数,ping报文发送的速度更快!
-f
,flood ping,此时如果不使用-i
设置间隔时间,就没有间隔,只有root可以这样使用。此模式下,ping显示出来的内容不一样:
For every ECHO_REQUEST sent a period “.” is printed, while for ever ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. If interval is not given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more. Only the super-user may use this option with zero interval.
貌似新版本对flood ping的时间间隔有修改。
可以与-c
参数配合,以方便估算丢包率!
-D
:输出的打印带上timestamp;如下
$ ping -D cs.pynote.net
PING cs.pynote.net (148.72.212.244) 56(84) bytes of data.
[1653719658.801393] 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=1 ttl=44 time=284 ms
[1653719659.652094] 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=2 ttl=44 time=285 ms
[1653719660.652086] 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=3 ttl=44 time=284 ms
[1653719661.662295] 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=4 ttl=44 time=294 ms
^C
--- cs.pynote.net ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 283.884/286.924/293.962/4.101 ms
下面是另一种给ping的输出打上timestamp的方法:
$ ping cs.pynote.net | while read pong; do echo "$(date): $pong"; done
Sat May 28 02:37:26 PM CST 2022: PING cs.pynote.net (148.72.212.244) 56(84) bytes of data.
Sat May 28 02:37:26 PM CST 2022: 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=2 ttl=44 time=274 ms
Sat May 28 02:37:27 PM CST 2022: 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=3 ttl=44 time=269 ms
Sat May 28 02:37:29 PM CST 2022: 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=5 ttl=44 time=275 ms
Sat May 28 02:37:30 PM CST 2022: 64 bytes from ip-148-72-212-244.ip.secureserver.net (148.72.212.244): icmp_seq=6 ttl=44 time=284 ms
关于ping协议的介绍。
在ping执行过程中,尝试输入Ctrl-\
,可以看到实时ping统计。
$ ping bing.com
PING bing.com (13.107.21.200) 56(84) bytes of data.
64 bytes from 13.107.21.200 (13.107.21.200): icmp_seq=1 ttl=112 time=41.8 ms
^\64 bytes from 13.107.21.200 (13.107.21.200): icmp_seq=2 ttl=112 time=47.1 ms
2/2 packets, 0% loss, min/avg/ewma/max = 41.842/44.448/42.493/47.055 ms
64 bytes from 13.107.21.200 (13.107.21.200): icmp_seq=3 ttl=112 time=41.8 ms
^\64 bytes from 13.107.21.200 (13.107.21.200): icmp_seq=4 ttl=112 time=41.9 ms
4/4 packets, 0% loss, min/avg/ewma/max = 41.837/43.158/42.347/47.055 ms
^\64 bytes from 13.107.21.200 (13.107.21.200): icmp_seq=5 ttl=112 time=41.8 ms
5/5 packets, 0% loss, min/avg/ewma/max = 41.789/42.884/42.277/47.055 ms
5/6 packets, 16% loss, min/avg/ewma/max = 41.789/42.884/42.277/47.055 ms
^C64 bytes from 13.107.21.200: icmp_seq=6 ttl=112 time=41.8 ms
--- bing.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5547ms
rtt min/avg/max/mdev = 41.789/42.711/47.055/1.942 ms
本文链接:https://cs.pynote.net/sf/linux/shell/202112098/
-- EOF --
-- MORE --