Sub topic 16
Tracing a packet's path and debugging forwarding
This chapter assumes you know IP prefixes, longest prefix match, next hops, TTL, and ICMP from earlier chapters. It also assumes you can use a Linux terminal. Here you will use those pieces to find out where a packet stops and why.
Start with the local routing decision
Before blaming the network, ask the sending host which route it would use. The kernel answers this directly.
# Which route, next hop, and source address would be used?
ip route get 8.8.8.8
# Show the whole table
ip route showIf the output names an unexpected interface or next hop, the problem is local. Common causes are a missing default route, a more specific route that overrides the one you expected, or a wrong prefix length.
Trace the path with traceroute
traceroute sends probes with TTL 1, then 2, then 3, and so on. Each router that drops a probe because the TTL reached zero returns an ICMP Time Exceeded message. The source address of that message identifies the hop.
traceroute 8.8.8.8Read the output
A line of * * * means no reply arrived for that hop. It does not always mean a failure. Many routers rate-limit ICMP or filter it, yet still forward your traffic. The real signal is whether later hops respond.
| Symptom | Likely cause |
|---|---|
| Stops at the first hop | The host's default route or gateway is wrong, or the gateway is down |
| Same two routers repeat | A routing loop, where each router's next hop points back at the other |
| Silent hops, then the path continues | A router that does not send ICMP; not a fault |
| Silent from one hop onward, destination unreachable | A drop at or after that hop, such as a missing route or a filter |
| Reports "Destination Net Unreachable" | A router has no matching route, including no default route |
Work through a failure
Suppose a host at 10.1.0.5 cannot reach 10.2.3.4, and traceroute shows hop 1 is the gateway 10.1.0.1 and then silence. Follow these steps.
- Run
ip route get 10.2.3.4on the host. It should show gateway 10.1.0.1. - Log in to the gateway and run the same command. If it chooses the default route toward the internet, the router has no route to 10.2.0.0/16.
- Add the missing route and check forwarding is enabled.
sudo ip route add 10.2.0.0/16 via 192.0.2.2 dev eth0
sysctl net.ipv4.ip_forwardIf net.ipv4.ip_forward is 0, a Linux machine receives packets but does not forward them. Set it with sudo sysctl -w net.ipv4.ip_forward=1.
Also remember the return path. The reply must find a route back to 10.1.0.0/16. A one-way fix produces the same symptom, because probes arrive but replies never return.
Exercise
A traceroute shows hops 1 to 3 normally, then the pattern "R2, R3, R2, R3" repeating until the maximum hop count. What is happening, and where do you look first?
Show answer
This is a routing loop. R2 sends the packet to R3 and R3 sends it back to R2, so the TTL falls until a router discards the packet. Check the routing tables on R2 and R3 for the destination prefix. Look for a static route or a default route on one router that points back at the other.
Exercise
ip route get 10.2.3.4 on a router shows it uses the default route, but you expect 10.2.0.0/16 to be used. Which two things do you check?
Show answer
First, whether a 10.2.0.0/16 route exists in ip route show. Second, whether that route is inactive, for example because its interface is down or its next hop is unreachable. Without a usable matching route, longest prefix match falls back to 0.0.0.0/0.