Linux下使用ping命令判断网络的好坏
简介
在Linux系统里面如果想判断网络的好坏,脑海中蹦出的第一个命令就是ping了。
ping命令基本是最常用的网络命令,它可以用来测试与目标主机的连通性。
ping通过发送ICMP ECHO_REQUEST数据包到网络主机,并显示返回的相应情况,根据这些信息就可以判断目标主机是否可以访问。
不过有些服务器为了防止通过ping探测到,可能会在防火墙或者内核参数中禁止ping命令,这样的话,可能虽然目标主机可以访问,但是无法ping通。
需要注意linux下的ping和windows下的ping稍有区别,linux下ping不会自动终止,需要按ctrl+c终止或者用参数-c指定要求完成的回应次数。
命令格式
ping [参数] [主机名或者IP地址]
使用范例
不加任何参数
如果不加任何参数,查看是否ping通
- ➜ ~ ping www.baidu.com
- PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
- 64 bytes from 115.239.210.27: icmp_seq=1 ttl=52 time=6.06 ms
- 64 bytes from 115.239.210.27: icmp_seq=2 ttl=52 time=5.56 ms
- 64 bytes from 115.239.210.27: icmp_seq=3 ttl=52 time=5.67 ms
- 64 bytes from 115.239.210.27: icmp_seq=4 ttl=52 time=5.82 ms
- 64 bytes from 115.239.210.27: icmp_seq=5 ttl=52 time=5.70 ms
- 64 bytes from 115.239.210.27: icmp_seq=6 ttl=52 time=5.79 ms
- --- 192.168.254.44 ping statistics ---
- 5 packets transmitted, 5 received, 0% packet loss, time 3999ms
- rtt min/avg/max/mdev = 0.152/0.159/0.172/0.017 ms
发送指定数目
可以通过 参数-c 来发送指定数目的包后停止
- ➜ ~ ping www.baidu.com -c 5
- PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
- 64 bytes from 115.239.211.112: icmp_seq=1 ttl=52 time=6.03 ms
- 64 bytes from 115.239.211.112: icmp_seq=2 ttl=52 time=5.96 ms
- 64 bytes from 115.239.211.112: icmp_seq=3 ttl=52 time=5.79 ms
- 64 bytes from 115.239.211.112: icmp_seq=4 ttl=52 time=5.79 ms
- 64 bytes from 115.239.211.112: icmp_seq=5 ttl=52 time=6.21 ms
- --- www.a.shifen.com ping statistics ---
- 5 packets transmitted, 5 received, 0% packet loss, time 4007ms
- rtt min/avg/max/mdev = 5.791/5.958/6.215/0.186 ms
设定发送间隔
可以通过 参数 -c 数目:在发送指定数目的包后停止
- ➜ ~ ping www.baidu.com -c 5 -i 2
- PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
- 64 bytes from 115.239.211.112: icmp_seq=1 ttl=52 time=6.06 ms
- 64 bytes from 115.239.211.112: icmp_seq=2 ttl=52 time=5.84 ms
- 64 bytes from 115.239.211.112: icmp_seq=3 ttl=52 time=5.98 ms
- ^C
- --- www.a.shifen.com ping statistics ---
- 3 packets transmitted, 3 received, 0% packet loss, time 4005ms
- rtt min/avg/max/mdev = 5.842/5.965/6.068/0.112 ms
相关推荐
higheels 2020-07-27
zlsh00 2020-02-19
txj 2020-09-08
travelinrain 2020-07-27
wq0 2020-07-18
Jieen 2020-07-08
luobotoutou 2020-06-16
屿刃 2020-06-14
TinyDolphin 2020-06-13
大老张学编程 2020-06-12
kenson 2020-06-08
PlayerL 2020-06-03
LeoHan 2020-05-31
wenjs00 2020-05-29
comeonxueRong 2020-05-17
furongwei 2020-05-04
BingGoGo技术 2020-04-07
wanggongzhen 2020-03-27