Linux Network Routing Best Practices

Tutorials · Published 2019-08-14 · Revised 2026-11-23
Reviewed corrections applied locally; original wording preserved separately · Joomla source

5,736 Total views across this article’s versions; includes the historical baseline where available.

Here are some brief concepts to keep in mind when adding new routes and routing tables.

Routing Table Names and IDs

The rt_tables file assigns names to numeric table IDs; it does not contain routes or determine lookup order. Keep these conventions in mind:

  1. Use unambiguous names and IDs that do not conflict with existing configuration.
  2. Keep the built-in mappings intact: local is 255, main is 254, and default is 253.
  3. IDs between 100 and 200 are a possible local convention, not a kernel requirement.
  4. Gaps between table IDs are optional. Rule priorities, not table IDs, control lookup order.

The ip-route manual describes table IDs and reserved values; ip-rule describes policy order.

Route Order

Arrange your saved configuration for readability. In a selected table, the longest matching destination prefix is the most specific route; command length and display order do not decide. Among otherwise comparable routes, lower metrics are preferred. Multipath routes require their own next-hop configuration.

Adding New Routes to an Existing Routing Table

To add a route to a custom table, identify it in the command. The routing type chart introduces route types; consult the installed ip route manual for the supported syntax.

A common choice on a server is the unicast route type. The command format to add a new unicast route is:

ip route add PREFIX via GATEWAY dev IFACE table TABLE_ID

This is a syntax template, not a command to paste unchanged. PREFIX is a destination such as 192.0.2.0/24 or default; GATEWAY is one reachable next-hop address, without a netmask. Direct routes can omit via. An optional src ADDRESS selects a preferred local source address; it does not perform source NAT.

Adding New Routes to the Default (main) Routing Table

To simply create a new route in the default routing table, just insert a new route in the table called main. This may be accomplished via the ip route command.

First, take a look at the current state of your main routing table.

ip route show

or

ip route show table main

or

route -n

The route metric is a 32-bit preference value, with lower values preferred among otherwise comparable routes. It is not limited to 65535. A low metric does not override a more specific eligible destination prefix.

Follow the instructions below to create new routes in the main table. To add a new route to the default main table, simply omit the table <table ID> portion of each command line.

Gateways

An IPv4 default route (0.0.0.0/0) is the least-specific route in its table. It can use a gateway or, where appropriate, a direct interface. A table does not have to contain one.

Multiple defaults can coexist, for example with different metrics, or as a multipath route with several next hops. Separate tables and policy rules are useful when the choice depends on traffic attributes such as source address. These mechanisms do not by themselves check whether a provider can still reach the Internet.

Split Gateways

Splitting a destination range uses ordinary prefix matching. For example, 0.0.0.0/1 and 128.0.0.0/1 together cover the IPv4 address space and are more specific than /0 in the same table. This does not bypass a one-gateway limit. It also does not guarantee equal traffic volume, working return paths, or failover. See Split Gateway Tutorial for the separately reviewed, bounded example.

Split routes should always be thoroughly vetted on a test or non-production system prior to implementation.