Troubleshooting lab: which hop is broken?
Start a local web service, then work through four safe, injected faults with ip, ping, dig, ss, curl and tracepath or traceroute, and name the failing layer or hop for each one from the evidence.
Contentsand lesson path
On this page
- Goal and setup
- The ladder you will use
- Step 1: Start the service and record a healthy baseline
- Step 2: Fault 1, a teammate gets refused
- Step 3: Fault 2, the service is gone
- Step 4: Fault 3, names stop resolving
- Step 5: Fault 4a, a host with no route
- Step 6: Fault 4b, the path stops after some hop
- Answer key and clean-up
- Check your understanding
- Apply it
- Review prompt
Lessons of Networking Basics
- Layers as a debugging map, and what L4 and L7 mean Concept · 15 min
- Addresses, CIDR blocks and the default gateway: DHCP, ARP and the next hop Worked example · 25 min
- From a name to a response: DNS, TCP and HTTP in one trace Worked example · 20 min
- Ports, NAT, firewalls, proxies and TLS along the path Concept · 20 min
- Troubleshooting lab: which hop is broken? Lab · 25 min
- Check: subnetting and failure triage Knowledge check · 8 questions
What you will learn
- Diagnose a connectivity failure with ip, ping, dig, ss, curl and traceroute, and name the failing hop or layer.
01. Goal and setup
To a user, Connection refused and timed out look alike, but they point to different places. In this lab you start a small web service, break the path to it in four ways, and for each fault write down the layer or hop that failed and the output line that proves it. An answer key follows the steps.
Every fault is local or harmless. You only send traffic to 127.0.0.1, to your own host address and to 192.0.2.0/24. That block is TEST-NET-1, which RFC 5737 reserves for documentation and keeps off the public Internet, so probes to it fail without reaching anyone's server. Do not point these commands at machines you do not own.
You need: a Linux machine or VM with iproute2 (ip, ss), iputils (ping, tracepath), dig (package dnsutils or bind9-dnsutils on Debian and Ubuntu, bind-utils on Fedora), curl and Python 3. Many distributions ship tracepath but not traceroute; either works. The outputs were recorded on Ubuntu 22.04 LTS with its packaged Python 3.10.12, curl 7.81.0, iproute2 5.15, iputils 20211215 and dig 9.18.39. Current upstream releases are newer (curl 8.23 and Python 3.15 in November 2026; Python 3.10 is past its upstream end of life, though Ubuntu still patches it). The commands work the same, and each step notes where newer tools word their output differently. Run every step in the same terminal: later steps reuse shell variables.
02. The ladder you will use
Work from the bottom of the stack up and stop at the first rung that fails. Each tool answers one question:
ip addrandip route get <address>: does this host have an address, and which route and next hop would a packet to that address use? If there is no route, the kernel refuses to send at all and you seeNetwork is unreachable.ping <address>: do ICMP echo packets get there and back? A reply proves the network layer (layer 3) path works; no reply is weaker evidence, because many hosts and firewalls drop ICMP on purpose.dig @<resolver> <name>: does the resolver answer? An answer, even a wrong one orNXDOMAIN(the name does not exist), proves the resolver is reachable. A timeout means the question never got an answer back.tracepath -nortraceroute -n: which routers on the way answer? Both send probes with a growing TTL (time to live). Each router lowers the TTL by one and reports back when it reaches zero, so each line is one hop. The last hop that answers shows roughly where packets stop. Silence from one hop is weak evidence alone: some routers ignore probes but still forward traffic.ss -tlnon the server: is a process listening on that port, and on which address?curl -v: does the application answer? Read the error.Connection refusedmeans a host sent back a TCP reset, so the path works but nothing accepts on that address and port (or a firewall rejects it).Connection timed outmeans nothing came back at all, which usually points to a drop on the path or a firewall that discards packets.
03. Step 1: Start the service and record a healthy baseline
Python's built-in web server serves the current directory. You bind it to 127.0.0.1, the loopback address, which only this machine can reach. $! holds the process ID (PID) of the last background command, so you can stop exactly this process later.
mkdir -p ~/net-lab && cd ~/net-lab
echo ok > health.txt
python3 -m http.server 18080 --bind 127.0.0.1 > server.log 2>&1 &
SERVER_PID=$!
sleep 1
ss -tln 'sport = :18080'
curl -sS -w 'status=%{http_code}\n' http://127.0.0.1:18080/health.txt
curl -sS -I http://127.0.0.1:18080/health.txt | head -n 2State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 127.0.0.1:18080 0.0.0.0:*
ok
status=200
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.10.12This is your baseline: one listening socket on 127.0.0.1:18080 and an HTTP 200. Each fault below changes one thing.
04. Step 2: Fault 1, a teammate gets refused
A teammate on another machine says the service refuses connections. You can do what they do: connect to your host's network address instead of loopback. hostname -I prints the host's addresses; the first one is usually the LAN address.
HOST_IP=$(hostname -I | awk '{print $1}')
echo "$HOST_IP"
ping -c 1 -W 1 "$HOST_IP" | grep 'bytes from'
curl -sS -m 3 "http://$HOST_IP:18080/health.txt"
ss -tln 'sport = :18080'192.168.225.201
64 bytes from 192.168.225.201: icmp_seq=1 ttl=64 time=0.033 ms
curl: (7) Failed to connect to 192.168.225.201 port 18080 after 0 ms: Connection refused
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 127.0.0.1:18080 0.0.0.0:*Write down your diagnosis first. Hint: compare the curl address with the Local Address column. Every curl version exits with code 7 and starts the line with curl: (7) Failed to connect to; the rest varies. curl 7 ends with Connection refused, curl 8.0 to 8.8 with Couldn't connect to server and 8.9 or later with Could not connect to server. From 8.21 the address reads 192.168.225.201:18080, not … port 18080.
05. Step 3: Fault 2, the service is gone
Now stop the server, as a crash or failed deploy would. wait collects the stopped process so no job message lands in your output.
kill "$SERVER_PID"; wait "$SERVER_PID" 2>/dev/null
ping -c 1 -W 1 127.0.0.1 | grep received
ss -tln 'sport = :18080'
curl -sS -m 3 http://127.0.0.1:18080/health.txt1 packets transmitted, 1 received, 0% packet loss, time 0ms
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
curl: (7) Failed to connect to 127.0.0.1 port 18080 after 0 ms: Connection refusedThe curl error is the same as in step 2, but ss now prints only its header line. That difference is the diagnosis, which is why you check the server before you blame the network.
06. Step 4: Fault 3, names stop resolving
Imagine a server whose nameserver line in /etc/resolv.conf points at 192.0.2.53, where no resolver will ever answer. @192.0.2.53 makes dig ask that server directly; +time=2 +tries=1 limits the wait to one two-second try.
dig @192.0.2.53 example.com +time=2 +tries=1
ip route get 192.0.2.53
ping -c 2 -W 1 192.0.2.53 | grep received;; communications error to 192.0.2.53#53: timed out
; <<>> DiG 9.18.39-0ubuntu0.22.04.8-Ubuntu <<>> @192.0.2.53 example.com +time=2 +tries=1
; (1 server found)
;; global options: +cmd
;; no servers could be reached
192.0.2.53 via 192.168.225.1 dev eno1 src 192.168.225.201 uid 1000
cache
2 packets transmitted, 0 received, 100% packet loss, time 1020msOlder dig releases print connection timed out; no servers could be reached instead. Note what ip route get proves: your host has a route and would send the packet to its gateway.
07. Step 5: Fault 4a, a host with no route
The last fault uses one unrouted address, 192.0.2.1, seen from two places. First, from a host with no routes at all. unshare -rn runs a command in a new, empty network namespace: a private copy of the network stack with only a loopback interface, which is down. Your real network is not touched. On many distributions this needs no root, but Ubuntu 24.04 and later restrict unprivileged user namespaces with AppArmor by default (the sysctl kernel.apparmor_restrict_unprivileged_userns is 1), so there the command fails with Operation not permitted. In that case use the sudo unshare -n form from the Troubleshooting box at the end of the lab.
unshare -rn sh -c 'ip route; ip route get 192.0.2.1; ping -c 1 192.0.2.1'RTNETLINK answers: Network is unreachable
ping: connect: Network is unreachableip route printed nothing: the table is empty, so there is no default route. The errors appear at once, without waiting for any timeout, because no packet was ever sent.
08. Step 6: Fault 4b, the path stops after some hop
Now ask your real host about the same address. -m 8 stops after eight hops so the trace finishes quickly. If you have traceroute instead of tracepath, run traceroute -n -m 8 192.0.2.1; it prints * * * where tracepath prints no reply.
ip route get 192.0.2.1
tracepath -n -m 8 192.0.2.1
curl -sS -m 5 http://192.0.2.1/192.0.2.1 via 192.168.225.1 dev eno1 src 192.168.225.201 uid 1000
cache expires 412sec mtu 1492
1?: [LOCALHOST] pmtu 1492
1: 192.168.225.1 0.479ms
1: 192.168.225.1 0.424ms
2: 203.210.148.18 2.911ms
3: 123.25.27.153 3.857ms
4: no reply
5: no reply
6: no reply
7: no reply
8: no reply
Too many hops: pmtu 1492
Resume: pmtu 1492
curl: (28) Connection timed out after 5001 millisecondsYour trace may stop at another hop, even right after your gateway: providers differ in how far they carry addresses that should not be routed. In our test run, busybox traceroute (from a container) showed the container bridge as hop 1, the same three routers, then * * *.
09. Answer key and clean-up
Compare your notes with these diagnoses.
- Fault 1 is on the server, at the transport layer (layer 4). Evidence:
pingto the host address works, so layer 3 is fine, andssshows the socket on127.0.0.1:18080, which does not accept connections to the LAN address. Fix the bind address (--bind 0.0.0.0), not the network. - Fault 2 is also layer 4 on the server. Evidence:
ssshows no listener at all. Find out why the process stopped (logs, crash, deploy) and start it again. - Fault 3 shows up as a DNS failure (layer 7), but the broken part is reaching the resolver. Evidence:
no servers could be reachedafter a timeout, whileip route getshows a route. The resolver address is wrong or the resolver is down. A wrong DNS record looks different: a fast answer with the wrong address, orNXDOMAIN. - Fault 4a is layer 3 on the local host: there is no route, so the packet never leaves. Evidence: an instant
Network is unreachablefromip route getandping. Fix the route table, usually a missing default route. - Fault 4b is layer 3 beyond your network. Evidence: the gateway and the next routers answer, then the trace goes silent and curl times out instead of being refused. The last hop that answered (here hop 3,
123.25.27.153) marks where to look: past it the address is not routed or is filtered, as RFC 5737 expects. With a real destination, you hand this evidence to whoever runs that part of the path.
Clean up with jobs (it should print nothing, because step 3 stopped the server) and cd ~ && rm -r ~/net-lab.
10. Check your understanding
11. Apply it
The skill practice asks for five injected faults in a two-network lab: a wrong DNS record, a missing route, a closed port, a firewall drop and an expired TLS certificate. Use this lab as the template and record the command, output line and layer or hop for each. Two are new here: a firewall drop makes curl time out, while a firewall reject usually looks like a closed port; an expired certificate passes every rung up to TCP and fails only in curl -v at the TLS step.
For intermittent loss, mtr --report --report-cycles 200 <host> gives loss per hop over 200 rounds. For slow calls, curl -sS -o /dev/null -w 'dns=%{time_namelookup} connect=%{time_connect}\n' <url> shows which stage takes the time.
12. Review prompt
Without looking back, explain how you told fault 1 from fault 2 when curl printed the same error for both. Then explain why Network is unreachable appears instantly while a dropped packet makes curl wait, and what the last answering hop in a trace does and does not prove.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.