The kernel decides where to send a packet by the routing table: each of its lines holds a network and the way to it.
A route is a line of the table: a destination network and the way to it. ip route prints the table. On the client from the first exercise it has a single line:
The kernel added this line by itself when lab0 got the address 192.0.2.10/24: its own subnet is reachable directly.
| Field | Meaning |
|---|---|
192.0.2.0/24 |
destination network |
dev lab0 |
the interface to send through |
proto kernel scope link |
added by the kernel, the network is directly connected |
src 192.0.2.10 |
the own address to send from |
There is no matching line for 198.51.100.20, so ping is refused at once.
A network behind a neighbour is described by a route with a gateway: the nearest host the packet is handed to. The gateway follows the word via:
The gateway must be a neighbour, in a connected subnet. ip route add rejects a gateway from another subnet: Error: Nexthop has invalid gateway.
The client's table contains this line. Where will the client send a packet for 203.0.113.5?
203.0.113.0/24 via 192.0.2.1 dev lab0
-
A route is exactly what another subnet needs: this line sends the whole
203.0.113.0/24through the gateway.ip route get 203.0.113.5shows the kernel's decision. -
viameans the packet is handed to the gateway192.0.2.1, which delivers it further. Only packets for your own subnet go directly, and those lines have novia.
The address after via is the gateway the packet is handed to, and the name after dev is the interface it leaves through. 203.0.113.5 is inside 203.0.113.0/24, so the line applies.
Key points
-
A route is a line of the table: a destination network and the way to it;
ip routeprints the table. -
The kernel adds the route to the subnet of its own address by itself:
proto kernel scope link. -
viais followed by the gateway, the neighbour a packet for the network behind it is handed to.