Day 4: Reachable?
Goal: From the message and the duration, you tell whether a port is open, whether nobody is listening, whether a firewall silently drops or rejects, and whether a host is missing – and you read
mtrso that you separate real packet loss from harmless gaps · Duration: approx. 75 min · Prerequisite: Day 3 including clean-up
Briefing
- “The server is not reachable” is not a diagnosis. A connection attempt ends in exactly one of a few ways, and each points to a different place: reply, rejection by the host, rejection by a firewall, silence, missing path.
- What matters is not only what is reported, but how fast. A rejection arrives in milliseconds, a missing neighbor after about 3 seconds, a dropped packet only after the program’s timeout.
pingis a poor witness for this. Many networks block ICMP, and a ping says nothing about a specific port. That is why today you test the port you actually need withnc, and the path to it withmtr.
Drill 1: Four Outcomes of a Connection Attempt
# on netz
# Open port
# nc netcat (OpenBSD variant, Ubuntu default)
# -z only establish the connection, send no data (port test)
# -v verbose: print success or error message
# -w3 wait at most 3 seconds for the connection to be established
sudo ip netns exec client nc -zv -w3 10.2.0.10 80
# Port on which nobody listens
sudo ip netns exec client nc -zv -w3 10.2.0.10 82
# Address in the target network that does not exist (5 seconds allowed)
# time measures how long the following command takes
time sudo ip netns exec client nc -zv -w5 10.2.0.99 80Expected (only the real line of
time is shown here):
Connection to 10.2.0.10 80 port [tcp/http] succeeded!
nc: connect to 10.2.0.10 port 82 (tcp) failed: Connection refused
nc: connect to 10.2.0.10 port 80 (tcp) failed: No route to host
real 0m3.091s
The last line refers to 10.2.0.99. What happened:
| Message | Who answers | Duration | Meaning |
|---|---|---|---|
succeeded |
target host, service | ms | port open, service accepts |
Connection refused |
target host (TCP reset) | ms | host is there, but nobody listens on this port – or a firewall answers with a reset (Drill 2) |
No route to host after ~3 s |
last router (ICMP host unreachable) | ~3 s | the router looked for the target via ARP and did not find it (Day 3) |
timed out |
nobody | the program’s timeout | packet vanishes: firewall drops, host off, return path broken |
Network is unreachable |
your own kernel | immediately | no route (Day 2) |
With -w2 instead of -w5, nc would have
given up after 2 seconds on the third test and reported
timed out – the router’s ICMP reply would have come too
late. So always choose a timeout that is longer than the ARP search (3
seconds).
Save your progress? Sign up for free
Drill 2: What a Firewall Makes of It
For this drill, web gets a second service on port 8080 and a firewall with three rules.
# on netz
# Second web server in web on port 8080 (like web-http on Day 0)
# --unit=web-alt name of the transient systemd unit
# --property=WorkingDirectory=/home/ubuntu/www working directory (index.html lives there)
# http.server 8080 --bind 10.2.0.10 port and address
sudo systemd-run --unit=web-alt --property=WorkingDirectory=/home/ubuntu/www \
ip netns exec web python3 -m http.server 8080 --bind 10.2.0.10
# Firewall in web: table fw for IPv4 and IPv6 (inet), chain in at the input
# add table inet fw new table fw in the inet family
# add chain inet fw in '{ type filter hook input priority 0; policy accept; }'
# chain for incoming packets to this host, default: accept
sudo ip netns exec web nft add table inet fw
sudo ip netns exec web nft add chain inet fw in '{ type filter hook input priority 0; policy accept; }'
# Rule 1: silently drop port 8080
sudo ip netns exec web nft add rule inet fw in tcp dport 8080 drop
# Rule 2: reject port 81 with ICMP “administratively prohibited”
# reject with icmpx admin-prohibited send back an ICMP error (icmpx: suitable for IPv4 and IPv6)
sudo ip netns exec web nft add rule inet fw in tcp dport 81 reject with icmpx admin-prohibited
# Rule 3: reject port 83 with a TCP reset
# reject with tcp reset answer as if nobody were listening
sudo ip netns exec web nft add rule inet fw in tcp dport 83 reject with tcp resetNow the same question to four ports:
# on netz
time sudo ip netns exec client nc -zv -w3 10.2.0.10 8080
time sudo ip netns exec client nc -zv -w3 10.2.0.10 81
time sudo ip netns exec client nc -zv -w3 10.2.0.10 82
time sudo ip netns exec client nc -zv -w3 10.2.0.10 83Expected (the message and the real line
for each command):
nc: connect to 10.2.0.10 port 8080 (tcp) timed out: Operation now in progress
real 0m3.048s
nc: connect to 10.2.0.10 port 81 (tcp) failed: No route to host
real 0m0.045s
nc: connect to 10.2.0.10 port 82 (tcp) failed: Connection refused
real 0m0.043s
nc: connect to 10.2.0.10 port 83 (tcp) failed: Connection refused
real 0m0.044s
Four lessons worth remembering:
- DROP (8080) looks like a host that is switched off: timeout. The service is running anyway.
- REJECT with ICMP (81) shows up as
No route to host– the same words as a missing host in Drill 1, but immediately instead of after 3 seconds. You recognize the firewall by the duration. - REJECT with TCP reset (83) cannot be told apart from “nobody listening” (82). From the outside you can only say: the host is there.
- A program like curl translates all of this once more into its own
words (
Couldn't connect to server). If you only read the application’s message, you lose the information.
You no longer need the firewall in web, but you do need the service on 8080 (Challenge):
# on netz
# delete table inet fw delete the table including chains and rules
sudo ip netns exec web nft delete table inet fw
sudo ip netns exec client nc -zv -w3 10.2.0.10 8080Expected:
Connection to 10.2.0.10 8080 port [tcp/http-alt] succeeded!
Save your progress? Sign up for free
Drill 3: Ping Is Not a Test
A network team blocks ICMP echo on the router “so that nobody can scan the network”.
# on netz
# Firewall on the router, chain for forwarded packets
# hook forward packets the router forwards (not those addressed to itself)
sudo ip netns exec router nft add table inet fw
sudo ip netns exec router nft add chain inet fw forward '{ type filter hook forward priority 0; policy accept; }'
# icmp type echo-request drop drop ping requests
sudo ip netns exec router nft add rule inet fw forward icmp type echo-request drop
# Ping says: dead
sudo ip netns exec client ping -c2 -W1 -q 10.2.0.10 | tail -2
# The service says: alive
sudo ip netns exec client nc -zv -w3 10.2.0.10 80Expected:
2 packets transmitted, 0 received, 100% packet loss, time 1032ms
Connection to 10.2.0.10 80 port [tcp/http] succeeded!
So always test the protocol and the port that matter. The same
applies to the path: mtr normally sends ICMP echo and fails
here as well. With -T it sends TCP SYN to a port:
# on netz
# mtr: traceroute and ping in one, measures each hop several times
# -n no name resolution
# -r report: print a table after the measurements instead of full screen
# -c5 5 measurements per hop
sudo ip netns exec client mtr -n -r -c5 10.2.0.10
# -T TCP SYN instead of ICMP echo
# -P 80 to this target port
sudo ip netns exec client mtr -n -r -c5 -T -P 80 10.2.0.10Expected (times differ, the Start: line
is omitted):
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.1.0.1 0.0% 5 0.2 0.2 0.2 0.3 0.0
2.|-- ??? 100.0 5 0.0 0.0 0.0 0.0 0.0
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.1.0.1 0.0% 5 0.5 0.4 0.3 0.5 0.1
2.|-- 10.2.0.10 0.0% 5 0.6 0.5 0.4 0.6 0.1
HOST: netz is the VM’s hostname; the namespaces share
it. ??? means: no reply came from this hop.
# on netz
# Remove the ICMP block again
# flush chain delete all rules of the chain, the chain stays
sudo ip netns exec router nft flush chain inet fw forwardSave your progress? Sign up for free
Drill 4: Real Packet Loss in mtr
Now the line to site B really loses packets. You simulate this with
tc netem on the router.
# on netz
# Drop 30 % of the packets the router sends via eth-b
# tc qdisc add dev eth-b root replace the queue on eth-b
# netem loss 30% network emulator: 30 % loss
sudo ip netns exec router tc qdisc add dev eth-b root netem loss 30%
# 20 measurements for usable statistics
sudo ip netns exec client mtr -n -r -c20 10.2.0.10Expected (the loss varies, with 20 probes between about 15 and 50 %):
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.1.0.1 0.0% 20 0.2 0.2 0.1 0.4 0.1
2.|-- 10.2.0.10 45.0% 20 0.2 0.3 0.2 0.4 0.1
This is how you read mtr: loss is real when it
starts at one hop and persists to the target. Here hop
1 is clean, from hop 2 on packets are missing – the problem lies between
the router and web. With more hops, every hop behind the fault would
also show loss.
# on netz
# Remove the fault
# tc qdisc del dev eth-b root restore the default queue
sudo ip netns exec router tc qdisc del dev eth-b rootFor comparison, a tool that works without root and without options and also reports the path’s MTU (more on that on Day 15):
# on netz
# tracepath -n path and path MTU, without name resolution
sudo ip netns exec client tracepath -n 10.2.0.10Expected:
1?: [LOCALHOST] pmtu 1500
1: 10.1.0.1 0.185ms
1: 10.1.0.1 0.044ms
2: 10.2.0.10 0.185ms reached
Resume: pmtu 1500 hops 2 back 2
Save your progress? Sign up for free
Exercise
Inject the fault and read the result without looking at the solution first:
# on netz
# sysctl -w net.ipv4.icmp_ratelimit=10000 minimum interval between ICMP error messages: 10,000 ms
sudo ip netns exec router sysctl -w net.ipv4.icmp_ratelimit=10000
sudo ip netns exec client mtr -n -r -c10 10.2.0.10A colleague sends you this output with the sentence “The router is losing 60 % of the packets”. Is he right? Justify your answer with the output and prove it with a second command.
Solution
Expected (the value at hop 1 varies, between 60 and 90 % in the test runs):
net.ipv4.icmp_ratelimit = 10000
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.1.0.1 60.0% 10 0.2 0.2 0.1 0.3 0.0
2.|-- 10.2.0.10 0.0% 10 0.2 0.2 0.2 0.4 0.1
No. Hop 2 has 0 % loss, even though every packet to it has to pass
through the router. If the router had really lost packets, they would
also be missing at the target (Drill 4). The gaps at hop 1 are missing
replies from the router itself: mtr only
learns about an intermediate hop through ICMP “Time exceeded”, and
routers throttle these messages. Here it answers at most every 10
seconds. Many routers on the internet do this out of the box, which is
why “loss at an intermediate hop, but not at the target” is the most
common false alarm in tickets.
Proof with a test that needs no replies from the router:
# on netz
# 20 pings to the target, all through the router
sudo ip netns exec client ping -c20 -i0.2 -W1 -q 10.2.0.10 | tail -2
# -i0.2 one packet every 0.2 seconds (instead of every second)
# Throttling back to the default (1000 ms)
sudo ip netns exec router sysctl -w net.ipv4.icmp_ratelimit=1000Expected:
20 packets transmitted, 20 received, 0% packet loss, time 3949ms
rtt min/avg/max/mdev = 0.167/0.220/0.363/0.040 ms
net.ipv4.icmp_ratelimit = 1000
Save your progress? Sign up for free
Challenge
Inject the fault:
# on netz
# Router rejects port 8080 and disguises it as “host unreachable”
sudo ip netns exec router nft add rule inet fw forward tcp dport 8080 reject with icmpx host-unreachableThe client reports “No route to host” for
10.2.0.10:8080. Prove three things without looking into a
firewall: (1) web is there, (2) something on web listens on 8080, (3)
which hop rejects the connection. Only then may you run
nft list ruleset on that hop and fix it.
Solution
# on netz
# Symptom with timing: immediate, so no ARP search
time sudo ip netns exec client nc -zv -w3 10.2.0.10 8080
# (1) web is there: port 80 answers
sudo ip netns exec client nc -zv -w3 10.2.0.10 80
# (2) something on web listens on 8080
# ss -ltn listening TCP sockets, ports as numbers (more on Day 5)
sudo ip netns exec web ss -ltn
# (3) which hop answers? traceroute with TCP SYN to exactly this port
# -T TCP SYN instead of UDP
# -p 8080 target port
# -q1 -w1 one probe per hop, wait 1 second (see Day 2)
sudo ip netns exec client traceroute -n -T -p 8080 -q1 -w1 10.2.0.10Expected:
nc: connect to 10.2.0.10 port 8080 (tcp) failed: No route to host
real 0m0.035s
Connection to 10.2.0.10 80 port [tcp/http] succeeded!
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 10.2.0.10:80 0.0.0.0:*
LISTEN 0 5 10.2.0.10:8080 0.0.0.0:*
traceroute to 10.2.0.10 (10.2.0.10), 30 hops max, 60 byte packets
1 10.1.0.1 0.190 ms
2 10.1.0.1 0.093 ms !H
At hop 2 it is not web that answers, but 10.1.0.1 once
more – with !H (host unreachable). The router pretends to
be the end of the path. Now looking into its firewall is justified:
# on netz
# list chain inet fw forward show only this chain
sudo ip netns exec router nft list chain inet fw forward
# Fix: remove the router's entire table fw (as in Drill 2 on web)
sudo ip netns exec router nft delete table inet fw
# Proof
sudo ip netns exec client nc -zv -w3 10.2.0.10 8080Expected:
table inet fw {
chain forward {
type filter hook forward priority filter; policy accept;
tcp dport 8080 reject with icmpx host-unreachable
}
}
Connection to 10.2.0.10 8080 port [tcp/http-alt] succeeded!
Save your progress? Sign up for free
Checkpoint
# on netz
# Router without its own firewall table fw, only the NAT table from Day 0
sudo ip netns exec router nft list tables
# no fault on eth-b
# tc qdisc show dev eth-b current queue
sudo ip netns exec router tc qdisc show dev eth-b | grep -c netem
# Router throttles ICMP normally again
sudo ip netns exec router sysctl -n net.ipv4.icmp_ratelimit
# Ping and both ports work
sudo ip netns exec client ping -c1 -W1 -q 10.2.0.10 >/dev/null && echo "ping ok"
sudo ip netns exec client nc -zv -w3 10.2.0.10 80
sudo ip netns exec client nc -zv -w3 10.2.0.10 8080Expected:
table ip nat
0
1000
ping ok
Connection to 10.2.0.10 80 port [tcp/http] succeeded!
Connection to 10.2.0.10 8080 port [tcp/http-alt] succeeded!
Clean up
# on netz
# remove the second service
# systemctl stop web-alt stop the transient unit (it disappears afterwards)
sudo systemctl stop web-alt
sudo ip netns exec web ss -ltn | grep -c 8080Expected:
0
Interview note
“What is the difference between Connection refused and Connection
timed out?” Refused: the target host (or a firewall with TCP reset)
actively answered, the path works. Timeout: nothing came back – firewall
with DROP, host off or return path broken. Bonus points:
No route to host can be a missing host (after ~3 s of ARP
search) or a firewall’s ICMP reject (immediately), and loss at an
intermediate hop in mtr is only real if it persists to the
target.
Enterprise note
DROP is considered “more secure” because attackers learn less. For your own teams, however, DROP costs the full timeout on every failure – often 30 to 120 seconds per attempt, minutes with retries. Many companies therefore use REJECT internally (fast, clear errors) and DROP at the external perimeter. And: if you block ICMP completely, you also block “Fragmentation needed” and thereby break Path MTU Discovery – the MTU black hole from Day 15.