Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Tracing a failing connection step by step

After this lesson: I can find where a connection fails by testing one step at a time.

55 min lesson11 commandsNAT gateway lab: masquerade and port forwarding with nftables in your browser

"The internet is down"

Network troubleshooting means finding where a connection fails by testing one step at a time, from the machine outward. It turns a vague complaint into one fault you can fix.

On Monday morning a manager rings the help desk. The internet is down. Ten minutes later it turns out only one printer was offline.

A good engineer does not guess. She tests each step in order and stops at the first one that fails.

By the end of this lesson

Note

I can find where a connection fails by testing one step at a time.

Key words

WordWhat it means
Symptomwhat the user sees go wrong
Default routethe way a machine sends traffic when no other route matches
Unreachableno route exists to that network
Timeoutno answer came back in time
Refusedthe machine answered and said no
Traceroutea tool that lists each router on the way

The cells students fill in are left blank in this preview.

Test one step at a time

A connection needs several things in a row: an address, a way to the gateway, a route, a path, a name and an open port. A fault at one step hides everything after it.

So test in that order. The first step that fails is where to look, and nothing after it is worth testing yet.

Worked example: the six steps

StepThe questionA command
1 AddressDoes this machine have an address?ip -br -4 addr
2 GatewayCan it reach its own gateway?ping the gateway
3 RouteDoes it know a way to the target?ip route get
4 PathWhere do the packets stop?traceroute -n
5 NameDoes the name turn into an address?dig, getent hosts
6 PortDoes something answer on the port?nc -zv, curl

The cells students fill in are left blank in this preview.

Step 1: read the LAN machine's address

Command
sudo ip netns exec lan ip -br -4 addr

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Step 2: ping the gateway

Command
sudo ip netns exec lan ping -c 1 -W 1 10.0.0.1

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Step 3: ask for the route

Command
sudo ip netns exec lan ip route get 203.0.113.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Break one step, then find it

Now you remove the LAN machine's default route yourself. Then you test the steps in order, and see which one fails first.

The last Run of this part puts the route back, so do all of it.

Remove the default route

Command
sudo ip netns exec lan ip route del default

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Step 2 again: the gateway still answers

Command
sudo ip netns exec lan ping -c 1 -W 1 10.0.0.1 | tail -n 2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Step 3 again: ask for the outside server

Command
sudo ip netns exec lan ip route get 203.0.113.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the web request says now

Command
sudo ip netns exec lan curl --noproxy '*' -sS -m 3 http://203.0.113.2:8000/; echo "curl exit code $?"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Put the default route back

Command
sudo ip netns exec lan ip route add default via 10.0.0.1

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Each failure word says something different

Unreachable comes at once and means there is no route. Refused comes fast and means the machine answered and said no.

A timeout comes slowly and means silence: a drop, or a reply that cannot find its way back. The next three Runs show the last two.

A refusal: the machine answered

Command
sudo ip netns exec gw nc -zv -w 2 10.0.0.2 9999; echo "nc exit code $?"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A timeout: nobody answers the LAN

Command
sudo ip netns exec lan curl --noproxy '*' -sS -m 3 http://203.0.113.2:8000/; echo "curl exit code $?"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Step 4: see where the packets stop

Command
sudo ip netns exec lan traceroute -n -q 1 -w 1 -m 3 203.0.113.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A common mistake

Warning

Many people think that if ping works the connection is fine. Ping proves one step only. The web request still needs a route back, a name and an open port. Here the gateway answers ping, and the web request still times out.

Worked example: from symptom to next step

What you seeWhat it meansWhere to look next
Network is unreachable, at onceNo route to that networkThe routing table and the default route
Could not resolve hostThe name gave no addressThe hosts file and the DNS server
Connection refused, fastThe machine is up and nothing listensThe program, its port and a reject rule
Timed out, slowlyNo answer came back at allA drop rule, or the way back

The cells students fill in are left blank in this preview.

Going further: your own order

Write down the six steps from this lesson in your own words, with one command for each.

Then pick a fault you have met, at work or at home, and say which step would have found it first. Keep the page: it is the start of your own checklist.