每天一个Linux命令:ping命令(检测目标主机的连通性)

ping命令用于检测目标主机的连通性,Linux的ping命令不会自动终止,需要按Ctrl+C取消。

语法:

ping [选项] [主机名或ip地址]

选项:

-i <秒数>:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次。
-s <字节数>:指定发送的数据字节数,预设值是56,加上8字节的ICMP头,一共是64ICMP数据字节。
-t <存活数值>:设置存活数值TTL的大小。

...
# 更多的选项可以用 man ping 来查看。

实例:

# 实例一:ping 目标主机(域名)

[email protected]:~# ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=63 time=75.0 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=63 time=39.3 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=63 time=39.4 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=63 time=38.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=5 ttl=63 time=44.2 ms
^C
--- baidu.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 38.299/47.265/75.013/14.024 ms


# 实例二:ping目标主机(ip地址)

[email protected]:~# ping 220.181.38.148
PING 220.181.38.148 (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148: icmp_seq=1 ttl=63 time=63.7 ms
64 bytes from 220.181.38.148: icmp_seq=2 ttl=63 time=86.8 ms
64 bytes from 220.181.38.148: icmp_seq=3 ttl=63 time=38.8 ms
64 bytes from 220.181.38.148: icmp_seq=4 ttl=63 time=74.1 ms
64 bytes from 220.181.38.148: icmp_seq=5 ttl=63 time=38.1 ms
^C
--- 220.181.38.148 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 38.114/60.367/86.866/19.296 ms


# 实例三:Ping目标主机(发送周期为 3秒,设置发送包的大小为1024字节,设置TTL值为 255)

[email protected]:~# ping -i 3 -s 1024 -t 255 220.181.38.148
PING 220.181.38.148 (220.181.38.148) 1024(1052) bytes of data.
1032 bytes from 220.181.38.148: icmp_seq=1 ttl=254 time=41.0 ms
1032 bytes from 220.181.38.148: icmp_seq=2 ttl=254 time=70.0 ms
1032 bytes from 220.181.38.148: icmp_seq=3 ttl=254 time=139 ms
1032 bytes from 220.181.38.148: icmp_seq=4 ttl=254 time=42.6 ms
1032 bytes from 220.181.38.148: icmp_seq=5 ttl=254 time=69.5 ms
^C
--- 220.181.38.148 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 12013ms
rtt min/avg/max/mdev = 41.053/72.476/139.037/35.558 ms
最后修改:2019 年 07 月 11 日 03 : 22 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论