A Practical Guide to Routing in the Linux Kernel

Routing and the Linux Kernel

This discussion will go behind the scenes of the routing engine in the Linux kernel.  We will explore how routing decisions are made, how the routing table is modified, as well as other useful hacks.

The referenced kernel is version 3.17.1.  With that being said, the well known traditional ‘routing cache’ has been removed (>= 3.6 kernel) in favor of the FIB TRIE database.

What is routing

Routing occurs when a machine wants to talk outside it’s local network or broadcast domain.  Routing is traditionally performed on destination IP addresses.  A simple way to think about routing is imagine a machine, 192.168.1.0/24 wanting to talk to a remote host, 4.2.2.1.  The machine will ask the following:

  • Is the destination, 4.2.2.1, inside my subnet?  No.  Continue.
  • Do I have a specific route to 4.2.2.1?  Essentially the machine is saying “I don’t know about 4.2.2.1, but does anything else know about it?”  This can either be a route to 4.2.2.1/32 or 4.2.2.0/24, or 4.0.0.0/8.  If not, continue.
  • Do I have a default gateway?  The default gateway is also known as the gateway of last resort.  The machine says “I don’t know about 4.2.2.1 so I’ll send it to this machine that knows how to get to all other hosts”.
  • Read More