How to inspect the routing table

Topic: Networking basics

Summary

View the kernel routing table with ip route or route -n so you can verify default route, directly connected networks, and static routes. Use this when debugging 'no route to host,' adding a new network, or confirming what path traffic will take. Interpret the output to see gateway and interface.

Intent: How-to

Quick answer

  • ip route or route -n shows the table; look for default via GATEWAY and for routes to specific prefixes; the first matching route (longest prefix) is used for each destination.
  • default via 192.168.1.1 dev eth0 means off-link traffic goes to that gateway via eth0; 192.168.1.0/24 dev eth0 proto kernel means that subnet is on-link on eth0 (no gateway).
  • If there is no default route, the host can only reach destinations that match other routes (e.g. on-link subnets); add default with ip route add default via GATEWAY (and make it persistent in netplan or NM).

Prerequisites

Steps

  1. List the routing table

    ip route or ip r; or route -n for numeric. Each line is a route: destination prefix, via gateway (if any), dev interface; 'default' is 0.0.0.0/0.

  2. Identify default and on-link

    Find the line 'default via X dev Y'; that is the default route. Lines with 'dev IF' and no 'via' are on-link (directly connected) subnets for that interface.

  3. Add or delete a route (temporary)

    ip route add default via 192.168.1.1; ip route add 10.0.0.0/8 via 192.168.1.1; ip route del default. Changes are lost on reboot unless made persistent in netplan or NM.

  4. Make routes persistent

    In netplan, set routes: under the interface or use routes: - to: 0.0.0.0/0 via GATEWAY; netplan apply. In NM, set ipv4.gateway or add routes in the connection.

Summary

Use ip route (or route -n) to view the routing table, confirm the default route and on-link networks, and add or remove routes. Use this when debugging reachability or configuring gateways and static routes.

Prerequisites

Steps

Step 1: List the routing table

ip route
route -n

Each line is one route: destination (prefix or default), optional via GATEWAY, and dev INTERFACE.

  • default via X dev Y: Default route; traffic to non-matching destinations goes to gateway X via interface Y.
  • 192.168.1.0/24 dev eth0 proto kernel: That subnet is on-link on eth0; no gateway needed for addresses in that range.

Step 3: Add or delete a route (temporary)

sudo ip route add default via 192.168.1.1
sudo ip route add 10.0.0.0/8 via 192.168.1.1
sudo ip route del default

These changes are lost on reboot unless made persistent.

Step 4: Make routes persistent

In netplan, add routes: under the interface with to: 0.0.0.0/0 and via: GATEWAY, then netplan apply. In NetworkManager, set the gateway or add routes in the connection profile.

Verification

  • ip route shows the expected default and any static routes; traffic to a test destination uses the expected path (check with traceroute if needed).

Troubleshooting

No default route — Add one with ip route add default via GATEWAY; make it persistent so it survives reboot.

Wrong gateway — Delete the route and add the correct one; ensure the gateway is on-link (same subnet as an interface).

Next steps

Continue to