ip route: Usage, Options & Common CI Errors
ip route shows the routing table - where packets to a destination actually go.
ip route is how you diagnose "Network is unreachable" in a container: usually a missing default route or wrong gateway. ip route get resolves which route a specific destination would take.
What it does
ip route displays and manipulates the kernel IP routing table. ip route show lists routes; ip route get <ip> shows the route a packet to that address would follow; ip route add/del manage routes, including the default gateway.
Common usage
ip route show # the full routing table
ip route # same, short form
ip route get 8.8.8.8 # which route would this use?
ip route show default # just the default route/gateway
ip route add default via 10.0.0.1 dev eth0Options
| Subcommand | What it does |
|---|---|
| show | Print the routing table |
| show default | Print only the default route |
| get <ip> | Resolve the route for a destination |
| add default via <gw> dev <if> | Set the default gateway |
| del <route> | Remove a route |
Common errors in CI
"Network is unreachable" almost always means there is no default route - check ip route show default; if empty, traffic off-subnet has nowhere to go. "RTNETLINK answers: Operation not permitted" adding a route needs NET_ADMIN. "RTNETLINK answers: File exists" means the route already exists (use replace, not add). In a container with a broken DNS but working routing, ip route get 8.8.8.8 succeeding while a hostname fails points the finger at DNS, not routing.