ArcLibrary

ping

Test 'reachable?' and 'how much latency?' — the first command in any network triage.

pingICMPRTT
核心 · Key Idea

In one line: ping uses ICMP Echo to test reachability between two hosts and reports round-trip time (RTT) and packet loss. It's the most basic command in network troubleshooting.

What it is#

ping's mechanic is simple: send an ICMP Echo Request, wait for the Echo Reply, measure RTT.

$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=12.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=11.9 ms
...
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 11.6/12.1/12.4/0.3 ms

Analogy#

打个比方 · Analogy

Shout "Hey! can you hear me?" — they reply "Yes!". You learn both that they're there and the rhythm of the echo.

Key concepts#

ICMPInternet Control Message Protocol
IP-layer control / error protocol; ping is built on it.
RTTRound-Trip Time
Round-trip latency — the `time=` field.
TTLTime To Live
Decrements once per hop, dropped at 0; ping's output `ttl` is the reply's TTL.
Packet lossPacket Loss
Of N pings, how many never returned.
MTU probingMTU Probing
Use `ping -s -M do` to find the link's max non-fragment size.

Practical notes#

  • ping -c 10 host: 10 packets then stop (Linux/macOS). Windows uses -n 10.
  • ping -i 0.2 host: every 0.2 s — measures bursty loss. Needs root.
  • ping -s 1472 -M do host: 1472-byte payload, no fragmentation — probes MTU.
  • ping6 / ping -6: tests IPv6.
  • Some networks block ICMP. "ping fails" doesn't mean the network is broken; try tcping or nc -vz host port.

Easy confusions#

ping fails
Could be: network unreachable / target blocks ICMP (firewall).
Service unreachable
Could be: network OK but service not listening / port blocked.
Verify with `nc -vz host port` or `telnet host port`.

Further reading#