Is order of network routes important in Linux?

The order in which routes are entered is, by definition, unimportant. This is due to how routes are supposed to be applied: the more specific ones have precedence over the more generic ones.

Suppose you have two routes:

  • a first one for a network, via gateway
  • a second one for a network, via gateway

When sending a packet to the machine with, say, IP address, the selected gateway will be always, independently from how the order the routes where entered in the system.

There is a catch, however: what about two routes for the very same network, but with different gateway? For example, consider this setup:

  • a first route for a network, via gateway
  • a second route for a network, via gateway

How would the system work? If you want a route to have preference over another otherwise identical route, you had to assign them a metric value. The metric is considered as a "cost" value, with lower metric preferred. So if your system has two otherwise identical routes but with different metric, it selects the route with a lower metric value.

But what happens if the two routes are identical even in the metric value? In this (corner) case, the default behavior is undefined and varies from system to system. For example, a system could prefer the fist entered route, while another system can give preference to the last entered one. Other systems can use both routes at the same time, distributing packets in a near round-robin fashion called ECMP (equal cost multipath routing). Finally, other systems can forbid the presence of two really identical routes, denying the possibily to even enter such routes.