- 用格式及用意
ping -c(设置 ping 的次数,默认无限次,可选) -i(设置 ping 的时间间隔,默认1秒,可选) -W(设置 ping 的超时时间,可选) 192.168.0.1
- 通过
ping 192.168.0.1
举例,也可以直接ping baidu.com
# 直接 ping,无限次,1秒一次 $ ping 192.168.0.1 PING 192.168.0.1 (192.168.0.1): 56 data bytes 64 bytes from 192.168.0.1: icmp_seq=0 ttl=64 time=0.077 ms 64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.090 ms 64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.109 ms 64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.115 ms 64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=0.100 ms 64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.097 ms ......
# 指定 ping 6次就结束,1秒一次 $ ping -c6 192.168.0.1 PING 192.168.0.1 (192.168.0.1): 56 data bytes 64 bytes from 192.168.0.1: icmp_seq=0 ttl=64 time=0.077 ms 64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.090 ms 64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.109 ms 64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.115 ms 64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=0.100 ms 64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.097 ms
# 指定 ping 2次就结束,2秒一次 $ ping -c2 -i2 192.168.0.1 PING 192.168.0.1 (192.168.0.1): 56 data bytes 64 bytes from 192.168.0.1: icmp_seq=0 ttl=64 time=0.077 ms 64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.090 ms
# 指定 ping 超时时间 $ ping -W0.1 192.168.0.1 PING 192.168.0.1 (192.168.0.1): 56 data bytes # 直接就不通了,因为时间太短