ping, traceroute & mtr
When a server can't reach something (or something can't reach the server), work along the path: is there a route, does the far end answer at all, where do packets get lost, and how long do they take? Network Troubleshooting gave the bottom-up method; this lesson is the server admin's toolkit for the path between hosts, and how to read what the tools say.
The error message is the first clue
Before reaching for any tool, read the error your client printed. Each one points at a different layer. The sandbox has only loopback and no default route, which is enough to produce the three classics:
echo "--- 1. no route to the network:"
ping -c 1 -W 1 10.0.0.1
echo "--- 2. host reachable, nothing listening on the port:"
curl -sS -m 2 http://127.0.0.1:9/
echo "--- 3. host reachable and answering:"
ping -c 3 -i 0.2 -q 127.0.0.1 | grep -E 'transmitted'--- 1. no route to the network:
ping: connect: Network is unreachable
--- 2. host reachable, nothing listening on the port:
curl: (7) Failed to connect to 127.0.0.1 port 9 after 0 ms: Couldn't connect to server
--- 3. host reachable and answering:
3 packets transmitted, 3 received, 0% packet loss, time 411ms
The second line is curl's wording for a refused connection: it failed after 0 ms, because the kernel answered at once with a TCP reset. Most other clients print Connection refused.
| Symptom | Means | Look at |
|---|---|---|
Network is unreachable |
no route at all from this host | ip route (missing default route, wrong netmask, interface down) |
No route to host |
an ICMP "host unreachable" came back, or ARP failed on the local network | is the target up? a firewall that REJECTs with icmp-host-prohibited? |
Connection refused |
the host answered with a TCP reset: it's up, but nothing listens on that port (or a REJECT rule) | ss -tln on the target (Listening Sockets) |
| timeout / hang | packets vanish: a DROP rule, a security group, a routing black hole | firewalls on both ends and in between, then traceroute |
Name or service not known |
DNS, not the network | DNS from the Server |
ping: is it alive, and how far?
ping sends ICMP echo requests. Its summary is what matters: packet loss and the round-trip time distribution.
# Sample session: from a server in Frankfurt to a database in the same region, and to a host abroad
$ ping -c 20 -i 0.2 -q 10.0.2.30
--- 10.0.2.30 ping statistics ---
20 packets transmitted, 20 received, 0% packet loss, time 3808ms
rtt min/avg/max/mdev = 0.412/0.538/1.104/0.161 ms
$ ping -c 20 -i 0.2 -q 198.51.100.80
--- 198.51.100.80 ping statistics ---
20 packets transmitted, 18 received, 10% packet loss, time 3812ms
rtt min/avg/max/mdev = 96.204/101.871/148.330/11.902 ms- Under 1 ms inside a data centre or cloud zone, a few ms between zones, tens to hundreds across continents. Physics sets the minimum: light in fibre needs about 1 ms per 100 km for the round trip.
- A high
mdev(jitter) or amaxfar aboveavgmeans queuing somewhere: congestion, or an overloaded host. - No reply is not proof that a host is down: many hosts and cloud security groups block ICMP. Test the real service port instead (
nc -zv host 5432,curl -v).
traceroute and mtr: where on the path?
traceroute sends probes with increasing TTL; each router that decrements the TTL to zero answers with "time exceeded", revealing itself. -n skips reverse DNS (much faster), -T -p 443 uses TCP SYNs to port 443 (needs root), which passes firewalls that drop UDP or ICMP probes:
traceroute -n 127.0.0.1traceroute to 127.0.0.1 (127.0.0.1), 30 hops max, 60 byte packets
1 127.0.0.1 0.020 ms 0.005 ms 0.004 ms
One hop on loopback. On a real path (sample session):
$ sudo traceroute -n -T -p 443 shop.example.org
traceroute to shop.example.org (203.0.113.40), 30 hops max, 60 byte packets
1 10.0.1.1 0.311 ms 0.288 ms 0.276 ms
2 100.65.12.1 1.020 ms 0.981 ms 1.004 ms
3 * * *
4 198.51.100.9 9.844 ms 9.812 ms 9.901 ms
5 203.0.113.1 18.201 ms 18.330 ms 18.140 ms
6 203.0.113.40 18.522 ms 18.497 ms 18.611 ms* * * on a middle hop with the path continuing afterwards is normal: that router simply doesn't answer probes. It only matters when every hop after a point is *.
mtr combines both: it traces once and then pings every hop continuously, which is what you want for intermittent problems. Run it in report mode for a ticket: mtr -rwzbc 100 host (report, wide, AS numbers, both names and IPs, 100 cycles). The skill is reading the loss column correctly. Routers rate-limit the ICMP replies they generate, so loss that appears at one hop and does not continue to later hops is an artefact; real loss starts at some hop and persists to the destination. This model applies that rule to two saved mtr reports:
def diagnose(report):
hops = [(int(n), host, float(loss), float(avg)) for n, host, loss, avg in (l.split() for l in report.strip().splitlines())]
final_loss = hops[-1][2]
if final_loss == 0:
noisy = [h for h in hops[:-1] if h[2] > 0]
note = f" (loss at hop {', '.join(str(h[0]) for h in noisy)} is ICMP rate limiting, ignore it)" if noisy else ""
verdict = "path healthy" + note
else:
# first hop from which every later hop shows at least the final loss
start = next(h for i, h in enumerate(hops) if all(x[2] >= final_loss * 0.8 for x in hops[i:]))
verdict = f"real loss of ~{final_loss:.0f}% starting at hop {start[0]} ({start[1]})"
jumps = [(b[0], b[3] - a[3]) for a, b in zip(hops, hops[1:]) if b[3] - a[3] > 40]
for hop, ms in jumps:
verdict += f"; latency jumps by {ms:.0f} ms at hop {hop}"
return verdict
# hop host loss% avg-ms
report_a = """
1 10.0.1.1 0.0 0.3
2 100.65.12.1 0.0 1.0
3 198.51.100.9 40.0 9.9
4 203.0.113.1 0.0 18.2
5 203.0.113.40 0.0 18.5
"""
report_b = """
1 10.0.1.1 0.0 0.3
2 100.65.12.1 0.0 1.0
3 198.51.100.9 0.0 9.8
4 192.0.2.77 12.0 96.4
5 203.0.113.1 11.0 97.0
6 203.0.113.40 12.0 97.2
"""
print("A:", diagnose(report_a))
print("B:", diagnose(report_b))A: path healthy (loss at hop 3 is ICMP rate limiting, ignore it)
B: real loss of ~12% starting at hop 4 (192.0.2.77); latency jumps by 87 ms at hop 4
Report B shows real loss and a big latency jump at hop 4 (an overloaded or long-distance link, often between two providers). That is the evidence your provider's support team will ask for: an mtr report from both directions if you can get one, because the return path is often different.
MTU problems: when small requests work and big ones hang
A classic: SSH logs in, curl of a small page works, but large downloads or TLS handshakes with big certificate chains hang. Some link on the path has a smaller MTU (VPNs, tunnels, some cloud networks), and the ICMP "fragmentation needed" messages that Path MTU discovery depends on are blocked by a firewall. Test with ping and the "don't fragment" flag (sample session):
$ ping -c 2 -M do -s 1472 10.8.0.5 # 1472 + 28 header bytes = 1500
ping: local error: message too long, mtu=1420
$ ping -c 2 -M do -s 1392 10.8.0.5 # 1392 + 28 = 1420 fits
64 bytes ... (normal replies)The fix is to let ICMP "packet too big"/"fragmentation needed" through (nftables accepts ICMP for this reason) or to lower the MTU or MSS on the tunnel interface.
Test yourself
A client gets Connection refused from the server. What does that tell you?
- The packet was dropped by a firewall
- The host is reachable and answered with a TCP reset: nothing listens on that port (or a REJECT rule)
- DNS failed
- There is no route
mtr shows 40% loss at hop 3, but 0% at hops 4, 5 and the destination. What is happening?
- Hop 3 is broken and must be reported
- Hop 3's router rate-limits the ICMP replies it generates; traffic passing through is fine
- The destination is down
- MTU problems
Small HTTP responses work, large ones hang, through a VPN. What is a likely cause?
- DNS caching
- A smaller MTU on the path with blocked ICMP fragmentation-needed messages (broken Path MTU discovery)
- Too many TIME-WAIT sockets
- A full disk