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 understand that traffic crosses routers to reach other networks. You should also have run ipconfig (or ip addr) to find your own address and default gateway. Reading the output in detail is the next chapter's job. Here you learn what ping does, which options matter, and how to use it to find where a connection fails.
What ping does
ping tests whether one host can reach another over IP and measures how long a round trip takes. It sends an ICMP Echo Request to the target. If the target is reachable and willing to answer, it returns an ICMP Echo Reply. ICMP is the Internet Control Message Protocol, which carries diagnostic and error messages at the IP layer. The tool records the time between sending the request and receiving the reply. This is the round-trip time (RTT).
A reply proves several things at once:
- Your host has a working network interface and a valid route toward the target.
- Every router on the path forwarded the request.
- The target received the request and chose to answer.
- Every router on the return path forwarded the reply.
A missing reply proves much less. The request may have been lost, the target may be down, or something may be filtering ICMP. Later sections cover how to tell these apart.
Ping works at the network layer. It does not test whether a web server, mail server, or any particular TCP or UDP port is working. A host can answer ping while its web service is down, and a host can ignore ping while its web service works fine.
Running ping
The basic form is ping followed by a target, which is either an IP address or a name. A name is first resolved to an address through DNS. If name resolution fails, ping reports an error and sends nothing. This is why the next chapter separates pinging by address from pinging by name.
Windows sends four echo requests by default and then stops. Linux and macOS send requests until you interrupt them with Ctrl+C.
ping -n 10 8.8.8.8
ping -t 8.8.8.8On Windows, -n sets the number of echo requests. -t pings until you stop it with Ctrl+C, which then prints the statistics. In a Windows console, Ctrl+Break prints the statistics so far and keeps going.
ping -c 10 8.8.8.8On Linux and macOS, -c limits the count. Without it, the command runs until interrupted. Use a fixed count in scripts so they terminate.
The common options differ between systems:
| Purpose | Windows | Linux / macOS |
|---|---|---|
| Number of requests | `-n count` | `-c count` |
| Run until stopped | `-t` | default behavior |
| Payload size in bytes | `-l size` | `-s size` |
| Do not fragment | `-f` | `-M do` (Linux), `-D` (macOS) |
| Interval between requests | not available | `-i seconds` |
| Timeout for each reply | `-w milliseconds` | `-W seconds` on Linux; `-W milliseconds` on macOS |
The Windows -w option is in milliseconds, and the Linux -W option is in seconds. A wrong unit is an easy mistake when you move between systems.
A quick tour of the output
A typical Windows result looks like this:
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=14ms TTL=117
Reply from 8.8.8.8: bytes=32 time=13ms TTL=117
Request timed out.
Reply from 8.8.8.8: bytes=32 time=15ms TTL=117
Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 13ms, Maximum = 15ms, Average = 14msThe fields to look at first:
timeis the RTT of that single request. Windows showstime<1mswhen the round trip took under a millisecond.TTLis the Time To Live value in the reply as it arrived. It is a rough hint about how many routers the reply crossed, and a later chapter explains it fully.Request timed out.means no reply arrived before the timeout expired. It does not say why.- The summary reports sent, received, and lost packets, plus minimum, maximum, and average RTT.
Packet loss is the share of requests that got no reply. A small, steady RTT with no loss is healthy. Large swings in RTT, or occasional loss, suggest congestion, a weak wireless link, or an overloaded device. The exact cutoffs depend on the network, so compare against a baseline you measured when things worked.
Replies that are not echo replies
A router or the target can answer your request with an ICMP error message instead of an Echo Reply. Ping prints these differently from a timeout:
Destination host unreachablemeans a router, or your own host, could not deliver the packet. If the message saysReply from 192.168.1.20: Destination host unreachable, the address in front is the device that generated the error. When that address is your own computer, there is no usable route or the local neighbor did not answer address resolution.Destination net unreachablemeans a router has no route to that network.TTL expired in transitmeans the packet's TTL reached zero before it arrived. This usually points to a routing loop or a very long path.General failureorTransmit failedusually points to a problem with the local interface, such as a disabled adapter.
The difference matters. A timeout is silence. An unreachable message is a device telling you something specific, and its source address tells you where the problem is.
The layered ping sequence
Instead of pinging a remote site and guessing at the failure, ping a series of targets that move outward from your machine. The first target that fails marks the stage to investigate.
ping 127.0.0.1
ping 192.168.1.1
ping 8.8.8.8
ping example.comIn this sequence, 192.168.1.1 is a placeholder. Use your own default gateway from ipconfig. You should also ping your own assigned address, which the topic's sequence includes between loopback and the gateway.
What each step tells you:
- Loopback (
127.0.0.1). The packet never leaves the machine. It tests the local TCP/IP software. Failure here is rare and points to the local stack or a host firewall rule. - Your own address. This confirms that the adapter is up and configured with the address you expect. Packets to your own address are also handled locally.
- Default gateway. This is the first device outside your host. A reply shows that your link to the local network works. A failure suggests a cable, Wi-Fi, switch, VLAN, or gateway problem, or a gateway that is configured not to answer ping.
- A remote IP address. A reply shows that routing through the gateway to the wider network works, without involving DNS. Public resolvers such as
8.8.8.8are common test targets because they usually answer ping. - A remote name. If the IP address works and the name does not, the fault is name resolution rather than connectivity.
Stop at the first failure and fix that stage. Testing later stages tells you little until the earlier ones pass.
Interpreting results by pattern
The same few patterns appear again and again.
| What you see | Likely meaning |
|---|---|
| All replies, stable RTT | Path works at the time of the test |
| Gateway replies, remote IP times out | Problem beyond your LAN, or ICMP is filtered somewhere |
| Remote IP replies, name fails with "could not find host" | DNS resolution problem |
| Intermittent timeouts with high RTT variation | Congestion, wireless interference, or rate limiting |
| `Destination host unreachable` from your own address | No usable local route or neighbor |
| `Destination host unreachable` from a router | That router could not forward the packet |
| First reply slow, later replies fast | Address resolution or a cache warming up, which is normal |
Do not read one timeout in a long run as an outage. Look at the loss percentage across enough requests. Ten to fifty requests give a better picture than four.
Common mistakes
- Treating a timeout as proof the host is down. Many firewalls and hosts drop ICMP echo requests on purpose. If other traffic to the host works, the ping failure is only the filter.
- Treating a reply as proof the service works. Ping does not test ports.
- Testing only by name. A failure by name hides whether DNS or connectivity broke. Test by IP address first.
- Using TTL as a precise hop count. Operating systems start TTL at different values, commonly 64, 128, or 255. The received value is a hint only.
- Judging a router by ping through it. Routers often give lower priority to ping addressed to themselves, so a high RTT to a router can be misleading. Traffic passing through it may be fine.
Probing path MTU with ping
Ping can also test the largest packet that crosses the path without being fragmented. The maximum transmission unit (MTU) is the largest IP packet a link can carry. On Windows, -f sets the Don't Fragment bit and -l sets the payload size.
ping -f -l 1472 8.8.8.8An IPv4 header takes 20 bytes and an ICMP header takes 8, so a 1472-byte payload makes a 1500-byte packet. If it succeeds, the path carries 1500-byte packets. If you see Packet needs to be fragmented but DF set., a link on the path has a smaller MTU. Lower the size step by step until replies return. The largest working payload plus 28 gives the path MTU. This test matters when large transfers stall on a VPN or tunnel while small packets work.
Exercise
You run ping 192.168.1.1 (your gateway) and get replies, then ping 8.8.8.8 and get Request timed out. on every attempt. A web browser also cannot load pages. What does this suggest, and what is your next step?
Show answer
The local link and gateway work, so the fault lies beyond your LAN, such as the router's uplink, the ISP, or a routing problem. DNS is not the cause, because you pinged by IP address. Next, run tracert -d 8.8.8.8 to see where the path stops, and check the gateway's WAN connection. Remember that a single ICMP-filtered target could also give this result, so try a second remote address.
Exercise
On Windows, which command sends exactly 20 echo requests with the Don't Fragment bit set and a 1400-byte payload to 8.8.8.8?
Show answer
ping -n 20 -f -l 1400 8.8.8.8