Skip to main content
p. 230

9.5 Routes and the Kernel Routing Table

Connecting internet subnets is mostly a process of sending data through hosts connected to more than one subnet. Returning to Figure 9-2, think about Host A at IP address 10.23.2.4. This host is connected to a local network of 10.23.2.0/24 and can directly reach hosts on that network. To reach hosts on the rest of the internet, it must communicate through the router (host) at 10.23.2.1.

The Linux kernel distinguishes between these two different kinds of destinations by using a routing table to determine its routing behavior. To show the routing table, use the ip route show command. Here’s what you might see for a simple host such as 10.23.2.4:

$ ip route show
default via 10.23.2.1 dev enp0s31f6 proto static metric 100
10.23.2.0/24 dev enp0s31f6 proto kernel scope link src 10.23.2.4 metric 100
note

The traditional tool for viewing routes is the route command, run as route -n. The -n option tells route to show IP addresses instead of attempting to show hosts and networks by name. This is an important option to remember because you’ll be able to use it in other network-related commands, such as netstat.

This output can be a little difficult to read. Each line is a routing rule; let’s start with the second line in this example, and break that into fields.

The first field you encounter is 10.23.2.0/24, which is a destination network. As with previous examples, this is the host’s local subnet. This rule says that the host can reach the local subnet directly through its network interface, indicated by the dev enp0s31f6 mechanism label after the destination. (Following this field is more detail about the route, including how it was put in place. You don’t need to worry about that for now.)

Then we can move back to the first line of output, which has the destination network default. This rule, which matches any host at all, is also called the default route, explained in the next section. The mechanism is p. 231 via 10.23.2.1, indicating that traffic using the default route is to be sent to 10.23.2.1 (in our example network, this is a router); dev enp0s31f6 indicates that the physical transmission will happen on that network interface.