Linux Labs

Networking / Stage 2 of 14

How Linux picks a route

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 7 · theory · 4 min

Ask the kernel about the path

ip route get shows which line of the table the kernel picks for an address. It sends no packets.

With the route from the exercise, the answer for the service is:

text
198.51.100.20 via 192.0.2.1 dev lab0 src 192.0.2.10 uid 0
    cache

The packet leaves through lab0 to the gateway 192.0.2.1 with the source address 192.0.2.10. uid 0 and cache are service fields that do not affect the path. With no matching line, ip route get prints RTNETLINK answers: Network is unreachable.

ip route get describes the client's decision; whether the packet arrived is what ping shows. A reply also needs a way back: the server sends it by its own table. Here the client is the server's neighbour in 192.0.2.0/24, so the way back exists by itself.

Check yourself 1 question

ip route get 198.51.100.20 printed 198.51.100.20 via 192.0.2.1 dev lab0 src 192.0.2.10. What follows from this?

Several options are correct.

  • ip route get sends no packets; it describes the choice of path. ping shows whether the host answers.

  • This is the client's table speaking. The server sends its reply by its own table, which you read on the server: sudo ip -n lab-server route.

ip route get shows the client kernel's decision: the gateway, the interface and the source address. Whether the packet arrived and a reply came back is what ping checks.

Key points

  • ip route get ADDRESS shows the chosen path: gateway, interface and source address.
  • ip route get sends no packets; ping checks the exchange.
  • The reply comes back by the other side's routing table.
Ubuntu 24.04
Loading…