Sub topic 4
Testing reachability with ping
This chapter assumes you know what an IP address is, can open a command prompt or terminal, and know that traffic between networks passes through routers. It also assumes you have read the ICMP chapter. Here you learn what ping does, how to run it, and how to use it to find where a connection fails.
What ping does
Ping tests whether another host answers you over IP. It sends an ICMP echo request to a target address and waits for an ICMP echo reply. It measures the time between the two, called the round-trip time (RTT).
A reply proves three things. Your packet reached the target, the target was willing to answer, and the reply found its way back. A missing reply proves less, because any of those three steps may have failed. A later chapter covers why.
Running ping
Give ping an IP address or a name:
ping 8.8.8.8
ping example.comThe default count differs by platform. Windows sends four echo requests and stops. Linux and macOS keep sending until you press Ctrl+C. Use these options to change that:
ping -n 10 8.8.8.8
ping -t 8.8.8.8On Windows, -n sets the number of requests. -t pings until you stop it with Ctrl+C. On Linux and macOS, -c sets the count:
ping -c 10 8.8.8.8A longer run gives a more reliable picture of packet loss and RTT variation than the default four packets.
The layered ping sequence
Do not start with a distant website. Ping a series of targets in order, from nearest to farthest. The first one that fails shows where the fault lies.
ping 127.0.0.1
ping 192.168.1.1
ping 8.8.8.8
ping example.comReplace 192.168.1.1 with your own default gateway, which ipconfig shows.
| Target | What a success proves | What a failure suggests |
|---|---|---|
| 127.0.0.1 (loopback) | The local IP stack works | The stack or a local firewall is broken |
| Your own IP address | The adapter is configured | Adapter or driver problem |
| Default gateway | Your local network link works | Cable, Wi-Fi, or wrong gateway setting |
| Remote IP address | Routing to the internet works | Problem at the gateway, the ISP, or beyond |
| Remote name | DNS resolution works | DNS server or settings problem |
The last two steps separate two kinds of problem. If ping 8.8.8.8 works but ping example.com fails, the network path is fine and name resolution is the problem.
Common mistakes
- Testing a name first. A failure then could be DNS or connectivity, and you cannot tell which.
- Trusting four packets. Intermittent loss can hide in a short run, so use
-n 20or-c 20when you suspect it. - Using the wrong gateway. The example
192.168.1.1is a placeholder. Read your real gateway fromipconfigorip route show. - Treating a timeout as proof of an outage. It only shows that no reply arrived.
Exercise
You run ping 8.8.8.8 and get replies, but ping example.com reports that it could not find the host. Which part of the layered sequence failed, and what does it tell you about the network path?
Show answer
The remote name step failed while the remote IP step succeeded. The network path to the internet works, so the fault is in name resolution. Check the DNS server addresses shown by ipconfig /all.
Exercise
Which option makes ping send exactly 10 echo requests on Windows, and which does the same on Linux or macOS?
Show answer
On Windows use ping -n 10 8.8.8.8. On Linux and macOS use ping -c 10 8.8.8.8.