Linux Networking F.A.Q.
3,827 Total views across this article’s versions; includes the historical baseline where available.
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?
For IPv4, a default route has destination prefix 0.0.0.0/0. It can name a next-hop gateway, or use an interface directly where that is appropriate, such as a point-to-point link. A default route and a default gateway are not quite the same thing.
Can I Set Up More than One Default Gateway?
Yes. A table can contain multiple default routes with different metrics, or a multipath default route with several next hops. Policy rules and separate tables can select defaults for different traffic. None of these arrangements alone proves that an upstream Internet connection is healthy.
What Does a Default Gateway Do, Exactly?
A default route covers destinations without a more specific eligible route in the selected table. If it names a gateway, packets use that next hop. Policy rules determine which table is consulted.
Default Routes in Custom Routing Tables
Yes, you can create a default route in a custom routing table.
For ordinary policy lookup to consult a custom table, a rule must select it. The built-in IPv4 rules normally select local, main, and default. You can also inspect a table directly with ip route show table TABLE_ID.
Which Routing Tables Have Built-in Support in the ip rule and ip route Commands?
The standard names include local (255), main (254), and default (253). Custom tables can be addressed numerically; these three names are not the complete set of possible tables.
How Do I Include Routes Inside Custom Router Tables?
A routing rule or route command can refer to a custom table by its numeric ID without first adding a name to rt_tables. Give a table a name there only if a readable alias helps manage it.
Can I Have Multiple Routes to the Same Destination in the Same Table?
Yes. Multiple routes can cover the same destination prefix, for example with distinct metrics. A multipath route can contain several next hops. A second otherwise identical ip route add may fail with “File exists”; changing the interface alone is not a general duplicate-route rule.
Local Routing Table Restrictions
The kernel normally maintains local-address and broadcast routes in table local. Address configuration through ip address affects those entries. Do not treat the old nat route type as a current option: route NAT has been unsupported since Linux 2.6. See ip-route(8).
What Is a “Broadcast” Route?
An IPv4 broadcast is addressed to all hosts on the relevant broadcast network. A broadcast route sends a link broadcast, whereas a unicast route selects a path toward an individual destination. Multicast is a separate mechanism for group delivery.
Address configuration normally maintains the relevant broadcast routes in the local table.
Main Routing Table Is the Default
Normal unicast routes added with ip route go into main when no table is specified. Some route types, including local and broadcast, default to table local. Specify a table explicitly when the distinction matters.
All routes in the main table may be modified or removed.
Automatic Routing Table Population on New Network Device
Assigning an address normally creates a connected-prefix route, unless options such as noprefixroute suppress it. Simply adding an interface does not discover arbitrary networks or create an Internet default route. Static configuration, DHCP, or another network service must supply that information. See ip-address(8).
Default Route Is Least Specific
An IPv4 default route has prefix length zero, so a more specific eligible route in the same table takes precedence. The position of a line in a displayed listing is not the lookup order. An earlier policy lookup can still select a default route before a later table is consulted.
Privileges Needed to Change Routes
Changing routes requires network-administration privilege, normally root or the appropriate CAP_NET_ADMIN capability in the relevant network namespace. See capabilities(7).
The Table Named default
The table named default (253) is distinct from main (254), and from a default route. It is normally empty, but the standard priority-32767 IPv4 rule consults it after the earlier default lookups. It can hold routes; that rule can also be removed. It is not an obsolete table that the kernel refuses to use.
Routing Table Names
The rt_tables file provides persistent name-to-number mappings for iproute2. It does not store kernel routes or rules, and editing it does not make them persistent.
Making Routes Persistent
Use the network configuration manager that controls the interface to persist both routes and rules. On a system using ifupdown, the following line illustrates a rule hook within the appropriate interface stanza:
post-up ip -4 rule add priority 100 from 192.168.30.200/32 lookup 100
This line adds only a rule. It does not populate table 100, configure an interface address, or handle repeated activation and cleanup. Use an unused priority and table, provide the required routes, and pair activation with cleanup in the chosen manager. Systems using Netplan, NetworkManager, or systemd-networkd need their own configuration.
What Is the Purpose of the ip_tables File?
There is no universal boot-generated configuration file named ip_tables. iptables manages rules in the kernel; saving and restoring them depends on the distribution or firewall service. See iptables(8) and Persistence: Making iptables Changes Stick.
What Is the Purpose of the rt_tables File?
rt_tables lists names for numeric routing table IDs so iproute2 can display and accept those names. It is not a master routing table, a list of all valid table IDs, or an execution order. The routing policy rules determine when a table is consulted.
What Is a FIB?
The Forwarding Information Base (FIB) is the kernel’s forwarding information used for route lookups, not a cache of recently used routes. Linux removed the old global IPv4 route cache in kernel 3.6; see ip-route(8). Changes made through ip rule or ip route update live kernel state. To survive a reboot they must be recorded in your network configuration or reapplied by its manager; a cache flush is neither a save operation nor a routing database reload.