ping is usually the first tool you reach for when something on a network seems broken. It sends ICMP echo requests to a host and waits for echo replies. The examples here use the Linux ping from the iputils package.
A first ping
ping -c 3 192.0.2.1PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
64 bytes from 192.0.2.1: icmp_seq=1 ttl=64 time=0.612 ms
64 bytes from 192.0.2.1: icmp_seq=2 ttl=64 time=0.587 ms
64 bytes from 192.0.2.1: icmp_seq=3 ttl=64 time=0.601 ms
--- 192.0.2.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.587/0.600/0.612/0.010 ms-c 3 sends three requests and stops. Without -c, Linux ping keeps going until you press Ctrl+C. Windows is different: it sends four by default and uses -n for the count.
Reading the output
icmp_seqnumbers each request. A gap suggests a lost reply.ttlis the Time To Live left in the reply when it reached you.timeis the round-trip time: out and back.56(84)means 56 bytes of data, which becomes 84 bytes with the ICMP and IPv4 headers.
The summary gives packet loss and the minimum, average, maximum and deviation of the round-trip times. Large swings between minimum and maximum point to an unsteady link.
Useful options
| Option | What it does |
|--------|--------------|
| -c N | Stop after N requests |
| -i S | Wait S seconds between requests |
| -s N | Send N bytes of data |
| -W S | Wait up to S seconds for a reply |
| -4 / -6 | Use only IPv4 or IPv6 |
Very short intervals may require root.
Narrowing down a fault
Work outward, one step at a time:
ping -c 2 127.0.0.1tests your own network stack.- Ping your default gateway (find it with
ip route). - Ping an IP address beyond the gateway.
- Ping a hostname such as
example.com.
If step 3 works but step 4 fails with Name or service not known, suspect name resolution (DNS) rather than the connection. The exact error text varies between versions.
Two other failures look different. Destination Host Unreachable means something, often your own machine or a router, reported that it could not deliver the packet. Pure silence ending in 100% packet loss means no replies and no error came back. Firewalls often cause this, so it does not prove the host is down.
Try it
Run the four steps on your own machine and note the average time for each. To practise fixing a routing fault, try Diagnose a broken default route.
Check your understanding
ping
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.