What you’ll get
Inspect the IPv4 routing table and ask ip route get exactly where the kernel sends packets to an external
server, a LAN neighbor, and a Docker container:
ip -4 route
# default via 10.0.0.1 dev eth0 proto static
# 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.11
# 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
ip route get 203.0.113.10
# 203.0.113.10 via 10.0.0.1 dev eth0 src 10.0.0.11 uid 1000
ip route get 10.0.0.12
# 10.0.0.12 dev eth0 src 10.0.0.11 uid 1000
ip route get 172.17.0.2
# 172.17.0.2 dev docker0 src 172.17.0.1 uid 1000
203.0.113.10 includes via 10.0.0.1 — the packet goes to gateway 10.0.0.1’s MAC. 10.0.0.12 and
172.17.0.2 have no via: the kernel delivers the frame directly over L2 after resolving the target MAC with
ARP (MAC, switch, ARP, and VLAN).
Each line in ip route is compact, and every token maps to a specific kernel decision:
ip route get <IP> shows the winning interface, gateway, and src.Longest prefix match (LPM) and the role of metrics
On a server with multiple NICs, Docker bridges, and VPN tunnels, several routing entries often match the same destination IP. Unlike a firewall ruleset, the kernel does not read the routing table top-to-bottom — it applies two rules:
- Longest Prefix Match (LPM). The most specific prefix wins:
/32beats/24,/24beats/16, and any route beatsdefault(/0). - Lowest metric (
metric). Metrics are compared only when prefix lengths are equal — for instance between twodefaultentries (metric 100beatsmetric 200).
Here is a table with overlapping prefixes where the narrower /24 deliberately carries a worse metric (500)
than /16 (10):
ip -4 route
# default via 10.0.10.1 dev eth0 metric 100
# default via 10.0.10.2 dev eth0 metric 200
# 10.20.0.0/16 via 10.0.10.2 dev eth0 metric 10
# 10.20.30.0/24 via 10.0.10.3 dev eth0 metric 500
# 10.20.30.5 via 10.0.10.4 dev eth0
ip route get 10.20.30.5 # -> via 10.0.10.4 (/32 — longest prefix)
ip route get 10.20.30.9 # -> via 10.0.10.3 (/24 beat /16 despite metric 500 > 10)
ip route get 10.20.50.1 # -> via 10.0.10.2 (outside /24, matched /16)
ip route get 203.0.113.10 # -> via 10.0.10.1 (two /0 routes — lower metric 100 won)
In ip route output, a /32 host route appears without a slash (10.20.30.5), yet the kernel treats it as a
32-bit prefix.
VPN clients (OpenVPN, WireGuard) rely on LPM for a well-known trick: to redirect all traffic into the tunnel
without deleting your existing default, they install two routes — 0.0.0.0/1 and 128.0.0.0/1. Together they
cover the entire IPv4 space, and /1 beats /0, so they override default. As soon as the tunnel drops and
those two entries disappear, your original default route takes over immediately.
The same rule explains why a Docker subnet colliding with your home LAN cuts off access
(Docker subnet clashes with home network): 192.168.0.0/20 dev br-… is longer than default (/0) and hijacks return
packets meant for the client.
Forwarding (ip_forward), return routes, and ip rule
An ordinary Linux server and a Linux router run the exact same networking stack. The key switch is
net.ipv4.ip_forward:
0(default on plain Linux): the kernel accepts packets addressed to its own IPs only; transit packets for other destinations are silently dropped.1(router, Docker host, or Proxmox NAT bridge): the kernel looks upDst IPin the routing table, decrementsTTLby1, rewrites the Ethernet header for the next hop, and sends the packet out the egress interface (Proxmox networking).
Each direction is routed independently. On the public internet, forward and return paths often cross different
transit ISPs, yet behind NAT or stateful firewalls the return path must go back through the same edge. If a
client sends SYN through a gateway but the server lacks a route back to the client’s subnet, the packet arrives
and the reply vanishes — always run ip route get on both ends when debugging.
Linux holds more than one routing table; ip rule decides which table to query:
ip rule show
# 0: from all lookup local
# 32766: from all lookup main
# 32767: from all lookup default
local(priority0) holds the host’s own addresses,127.0.0.0/8, and broadcast entries — which is why they do not appear in plainip route.main(32766) is the primary table displayed byip route.- Between them, you can insert policy routing rules (for example, on a dual-ISP server so replies leave through the same interface the request came in on).
TTL, traceroute, and mtr: how routers along the path show up
The TTL field (Time To Live, 1 byte in IPv4; called Hop Limit in IPv6) caps how many routers a packet may
cross. Linux starts at 64 (sysctl net.ipv4.ip_default_ttl), Windows at 128, and many network appliances at
255.
Every router on the path subtracts 1 from TTL. When it reaches zero, the router drops the packet and returns
ICMP Time Exceeded (type 11, code 0) with its own IP as the source. Without TTL, any routing loop (router
A forwards to B and B forwards back to A) would spin a packet forever.
Watch TTL in action with ping -t 1 (sets TTL = 1):
# Normal ping across one router (TTL 64 dropped to 63):
ping -c 1 10.0.20.10
# 64 bytes from 10.0.20.10: icmp_seq=1 ttl=63 time=0.050 ms
# Same ping with TTL=1 — stopped at the very first router 10.0.10.1:
ping -c 1 -t 1 10.0.20.10
# From 10.0.10.1 icmp_seq=1 Time to live exceeded
On the router’s ingress interface, tcpdump -nn captures that two-packet exchange:
# 18:43:36.370928 IP 10.0.10.10 > 10.0.20.10: ICMP echo request, id 3979, seq 1, length 64
# 18:43:36.370949 IP 10.0.10.1 > 10.0.10.10: ICMP time exceeded in-transit, length 92
traceroute, tracepath, and mtr all build on this mechanism: send probes with TTL = 1 (hop 1 answers),
then TTL = 2 (hop 2 answers), TTL = 3, and so on until the target itself replies. Ubuntu includes mtr and
tracepath out of the box: mtr -rwc 20 example.org runs 20 cycles and prints per-hop loss and latency.
- Client (TTL 64)✓ via 10.0.10.1
- Router 1✓ TTL 64 > 63
- Router 2✓ TTL 63 > 62
- Server✓ reply (TTL 62)
64 bytes from 10.0.20.10: icmp_seq=1 ttl=63 time=0.050 ms
Each router picked the next hop by LPM, decremented TTL by 1, rewrote MAC addresses, and forwarded the packet.
ip route get 10.0.20.10
- Client (TTL 1)✓ probe >
- Router 10.0.10.1✕ TTL = 0 (dropped)
- ICMP Time Exceeded✓ < from 10.0.10.1
- Server— not reached (by design)
18:43:36.370928 IP 10.0.10.10 > 10.0.20.10: ICMP echo request, id 3979, seq 1, length 64 18:43:36.370949 IP 10.0.10.1 > 10.0.10.10: ICMP time exceeded in-transit, length 92
The router decremented TTL to zero and returned ICMP time exceeded in-transit from its own address — that is how traceroute and mtr discover each hop.
ping -c 1 -t 1 10.0.20.10 or mtr -rwc 10 203.0.113.10
- Hop 1 (gateway)✓ Loss 0%
- Hop 2 (backbone)✕ Loss 60% (ICMP)
- Hop 3 (ISP)✓ Loss 0%
- Server✓ Loss 0%
HOST: web1 Loss% Snt Last Avg Best Wrst 1.|-- 10.0.0.1 0.0% 20 0.2 0.2 0.1 0.4 2.|-- 198.51.100.1 60.0% 20 4.1 4.3 3.9 5.0 3.|-- 203.0.113.1 0.0% 20 11.2 11.4 10.9 12.1 4.|-- 203.0.113.10 0.0% 20 12.0 12.1 11.8 12.9
Hop 2 rate-limits ICMP Time Exceeded replies to save CPU, yet forwards transit packets cleanly — proven by 0.0% loss at hops 3 and 4.
Check the loss column on the last line of mtr -rwc 20 203.0.113.10
- Client✓ packet >
- Linux gateway✕ ip_forward = 0
- Second network— silence
- Server— never arrived
# On the client: 1 packets transmitted, 0 received, 100% packet loss # On the Linux gateway: sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 0
The gateway’s Linux kernel received the packet, but forwarding is off — transit traffic is dropped silently before the firewall.
sysctl net.ipv4.ip_forward on the gateway
If it doesn’t work
Added a route with a low metric (10), yet traffic still leaves via a route with metric 500
- Cause
- The route with metric
500has a longer prefix (for example/24vs/16or/0). Metrics break ties only among routes with the same prefix length. - Fix
- Check the kernel’s decision for a specific address with
ip route get 10.20.30.9. To override a narrower prefix, add a route with an equal or longer mask.
mtr shows 40–100% loss or ??? on an intermediate hop, while the final server shows 0% loss
- Cause
- Intermediate routers rate-limit ICMP
Time Exceededgeneration or drop probes to their control plane while forwarding transit traffic without loss. - Fix
- Read packet loss on the final hop and the rows after the suspect hop: real loss carries all the way to the bottom, whereas loss confined to one middle row is ICMP rate limiting on that router.
A two-interface Linux host is reachable from both networks, yet packets will not pass between them
- Cause
- IPv4 forwarding is disabled in the kernel (
net.ipv4.ip_forward = 0by default on stock Linux without Docker), or the firewall’sforwardchain drops transit packets. - Fix
- Check
sysctl net.ipv4.ip_forward(must be1for routing; persist it in/etc/sysctl.d/) and inspect theforwardrules insudo nft list ruleset.
Starting a VPN dropped your SSH session to the server or cut off access to the local network
- Cause
- The VPN installed
0.0.0.0/1and128.0.0.0/1(together they cover all of IPv4 and beatdefault/0), or a route covering the client subnet sent replies into the tunnel. - Fix
- Run
ip route get <client-ip>: if replies leave via the tunnel instead ofeth0, add an explicit/32route for your management IP through the old gateway, or configure policy routing (ip rule).
ping or curl immediately fails with Network is unreachable even though the interface is UP
- Cause
- No entry in the routing table matches the target address — usually the
default(0.0.0.0/0) route is missing. - Fix
- Check
ip -4 route: if there is nodefault via …line, inspect DHCP/netplan settings or add the gateway withsudo ip route add default via 10.0.0.1 dev eth0.