6

On one of my web server the loopback route is in 2nd position and usually it is in 3rd position on other server when displaying the routes:

>ip route show

Results on what is displayed on one centos 7 server:

default via 85.x.x.254 dev enp32s0 
85.x.x.192/26 dev enp32s0  proto kernel  scope link  src 85.x.x.201 
169.254.0.0/16 dev enp32s0  scope link  metric 1002 

Result for another centos 7 server:

default via 217.x.x.1 dev em1 
169.254.0.0/16 dev em1  scope link  metric 1002 
217.x.x.0/24 dev em1  proto kernel  scope link  src 217.x.x.216 

Does it make any differences? Does it have any consequences? Can anyone explain why it happens?

  • 2
    I don't think it means anything. On newer systems I see them ordered starting with shorter prefixes and ending with longer prefixes. On older systems it's the other way around with the longer prefixes first and the shorter prefixes last. The first of your lists seems a bit unusual in that the longest prefix is in the middle. Remember that `default` is synonymous with `/0`. – kasperd Apr 24 '16 at 11:17

2 Answers2

12

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 172.16.0.0/16 network, via gateway 192.168.1.1
  • a second one for a 172.16.32.0/24 network, via gateway 192.168.1.2

When sending a packet to the machine with, say, 172.16.32.1 IP address, the selected gateway will be always 192.168.1.2, 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 172.16.32.0/24 network, via gateway 192.168.1.1
  • a second route for a 172.16.32.0/24 network, via gateway 192.168.1.2

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.

eranga
  • 164
  • 1
  • 11
shodanshok
  • 44,038
  • 6
  • 98
  • 162
-3

Yes, the ordering of network routes is important independently of operating system in general.

Routes are programs. They say, when you get a packet that is addressed to network A, use router A to do it. When you get one for B, use router B.

Let's say that A is inside of B, like A = 192.168.1.0/24 and B = 192.168.0.0/22. Then if we reverse the ordering of routes being applied, A would have no effect, because all of A is inside B. On the other ahdn , int this ordering, even though B is second, the route still affects B because 75% of its hosts are not in A.

The ordering of route application in this context (static routes) is done via static metrics. The smallest metric (cheapest route) gets to go before.

tacos_tacos_tacos
  • 3,220
  • 16
  • 58
  • 97
  • No, this isn't accurate. The most specific (longest prefix) route which matches the destination is used. Only if there are multiple equally specific routes the metric will matter. See eg https://serverfault.com/questions/648276/routing-selection-specificity-vs-metric – Håkan Lindqvist Apr 24 '16 at 15:41