Linux Networking F.A.Q.

What is the purpose of routing tables?

Routing tables inform the Linux kernel where to find destinations on a network. They describe information such as which network interface to send a packet on, and whether the destination is local (on a local network) or remote.

How do you define a "default" gateway?

The default gateway is defined by destination and genmask on the same route, for the same network interface, in a routing table. The gateway assignment on that line in the routing table will be treated as the default (path) gateway.

Can I setup more than one default gateway?

Yes. It's a little complicated. You are limited to one default gateway per interface in each routing table. There is also an advanced technique called "splitting" a single default gateway that makes it possible to segment your default gateway on a single interface. The preferred method of incorporating multiple gateways is to utilize a combination of independent custom routing tables with routing rules (via iprules and iptables).

What does a default gateway do, exactly?

A default gateway directs outbound network packets to remote routers when a route for the packet cannot be found locally, and a specific destination path is not found.

Default routes in custom routing tables

Yes, you can create a default route in a custom routing table.

Any route name besides main or local must be pointed to by a rule, established with the ip rules command.

Which routing tables have built-in support in the ip rule and ip route commands?

Main, local, and default.

How do I include routes inside custom router tables?

Tables other than the built-in ones: main, local, and default; must be added to the Master Routing Table before they can be used. The MRT does not reset on system reboots.

Can I have multiple routes to the same destination in the same table?

Yes, you can map the same destination IP address to multiple routes in the same routing table. For practical purposes, a single routing table may contain multiple routes to the same destination if the ToS differs on each route or if the routes apply to different interfaces.

Local Routing Table Restrictions

You may only have local, nat, and broadcast route types in the local routing table.

The local table may be manipulated with the ip address and ifconfig commands.

What is a "broadcast" route?

A broadcast is a message sent to a group of devices on a local network. The broadcast route type is the opposite of a unicast route, which sends a packet to a single, specific IP address. The vast majority of routes are of the unicast route type.

Broadcast routes should be confined to the local table.

Main Routing Table is the Default

Changes made to a routing table via the iproute command will be applied to the main table by default if no table name is specified.

All routes in the main table may be modified or removed.

Automatic Routing Table Population on New Network Device

The main table is auto-populated by the kernel when a new interface is added to a device. The kernel will automatically add routes to any known local area networks and a default route.

Default Route Always Last

The default route ( with a netmask of is the least specific possible route. Therefore, its filter will always be applied last.

Only Super Users May Add New Routes

Non-super users cannot add entries to the local routing table, or modify existing entries.

Default Routing Table Is Obsolete

The routing table named default is a legacy product of the original iproute process. It is not used and may be ignored, but not deleted.

Master Routing Table

The Master Routing Table stores the names of all routing tables. It is a file named rt_tables file. It's location may vary slightly depending on Linux distribution, but is almost always found under the iproute2 directory. Its contents are persistent across reboots.

Making Routes Persistent

To make custom router tables persistent across reboots, insert a line like this into /etc/network/interfaces:

post-up ip rule add from lookup custom

What is the purpose of the ip_tables file?

The ip_tables file contains your iptables configuration. It is created on boot. If you modify it, the file will reset to its default settings on reboot.

What is the purpose of the rt_tables file?

What is the rt_tables file used for? It is the Master Routing Table. It keeps track of which routing tables are legitimate, not which get processed or when.

What is a FIB?

Linux maintains a routing cache (also known as the Forwarding Information Base or "FIB"). The cache stores recently used routes and - most importantly from our perspective - this is where any changes you make to Linux' built-in routing table occur. This is one of the perhaps strange things about Linux routing. Whatever changes you make using ip rule or ip route are not stored permanently. They must be re-loaded whenever the routing caches is flushed, such as on server restart.