ping 发送 ICMP 回显请求来测试网络连通性。
ping 使用 ICMP 协议向目标主机发送回显请求包,并等待回显应答。它测量往返时间(RTT)并报告丢包率,是网络故障排查的首选工具。
示例 1:基本 ping
ping google.com
PING google.com (142.250.72.14) 56(84) bytes of data.
64 bytes from 142.250.72.14: icmp_seq=1 ttl=116 time=14.2 ms
64 bytes from 142.250.72.14: icmp_seq=2 ttl=116 time=14.5 ms
64 bytes from 142.250.72.14: icmp_seq=3 ttl=116 time=14.3 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 14.200/14.333/14.500/0.124 ms
示例 2:指定次数
ping -c 5 example.com
示例 3:指定超时(每包等待 2 秒)
ping -W 2 -c 3 192.168.1.1
示例 4:每 3 秒发送一个包
ping -i 3 192.168.1.1
示例 5:以 10 秒为整体超时
ping -w 10 example.com
示例 6:测试 IPv6
ping -6 ipv6.google.com
示例 7:泛洪模式(需要 root)
ping -f -c 100 target.com
| 参数 | 长参数 | 说明 |
|---|---|---|
-c COUNT |
发送 COUNT 个包后退出 | |
-i SECONDS |
包间间隔(默认 1 秒) | |
-W SECONDS |
每个包的超时时间 | |
-w SECONDS |
总超时时间 | |
-s SIZE |
包大小(数据字节数,默认 56) | |
-t TTL |
设置 TTL 值 | |
-4 |
使用 IPv4 | |
-6 |
使用 IPv6 | |
-f |
泛洪模式(需要 root) | |
-q |
静默模式,只输出总结 | |
-a |
响铃提示 | |
-v |
显示详细信息 | |
-n |
不解析主机名,只显示 IP | |
-I INTERFACE |
指定网络接口 |