Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a following up question to an question I found answered on unix.stackexchange.com (see link below).


What is the difference between the following two routing table entries:

default            E.F.G.H     UGSc            0        0     en1
default            E.F.G.H     UGScI          25        0     en1

(Where E.F.G.H is some gateway IP address.) Specifically what effect does the RTF_IFSCOPE flag have on the routing table entry?

Source: Routing Tables: What is the effect of the RTF_IFSCOPE flag?


The accepted answer then is that the second route is "bound to a specific interface" and this can be used to "create multiple routes that point to the same destination, differentiated only by which interface is in play"

OK, but what does that mean? Let's say I have the following (as I really do, only changed the IPs):

default            192.168.1.1        UGSc           14        0     en2
default            192.168.0.1        UGScI           1        0     en0

Under what circumstances will the second route be used? Or more generally when will the "I" route be used? The "real" default route seems to be the one without the "I". Because:

$ route get 8.8.8.8
    route to: google-public-dns-a.google.com
destination: default
       mask: default
    gateway: 192.168.1.1
  interface: en2
      flags: <UP,GATEWAY,DONE,STATIC,PRCLONING>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0 

Btw: I know about the following from man netstat:

I       RTF_IFSCOPE      Route is associated with an interface scope

But I do not understand it :(

Any hints are much appreciated!

share|improve this question

2 Answers 2

Using the route command's -ifscope option binds a route to a specific interface, which shows in netstat output with the I flag.

The decision on when to use your second route will be by its IP address and metrics, or if requested directly. In case of duplicate IP addresses, the best route is chosen which may not be by the bound interface. A syntax exists for forcing the usage of a given interface, but I don't know exactly which operating systems or utilities support this syntax. This applies usually more to iPv6.

Example on how to specify scope information:

  • When the scope information is an interface name :

    ping fe80::1%eth0

  • When the scope information is an interface index :

    ping fe80::9:47:100:112%65541

The decimal value 65541 is interpreted by the operating system according to its algorithms (not a good idea to use).

share|improve this answer
    
The decision on when to use your second route will be by its IP address and metrics, or if requested directly. –  scherand Jul 1 '12 at 2:01
    
I think the magic is in this sentence: The decision on when to use your second route will be by its IP address and metrics, or if requested directly. In my little example I have two default routes. Do you mean the second one would be used for something like ping -I <IP of en0> 8.8.8.8 (i.e. interface requested directly)? What is the meaning of "by its IP address and metrics"? –  scherand Jul 1 '12 at 2:09
1  
Metric="cost". For an IP, a route is used if : (1) requested by name, or if name not specified, (2) It is the only one for the IP, or in case of duplicates (3) its metric is the lowest, or if metrics are equal, (4) by whatever operating system algorithms. The usual method is to set the metric of the route you don't prefer to higher. See for example this and this. –  harrymc Jul 1 '12 at 6:50
    
OK, I understand (2), (3) and (4). But not (1) really. If we stick to the example of ping -I <IP of en0> 8.8.8.8 would the -I throw me into case (1)? Is -I "requesting by name"? Also from what I see there are no different metrics (or can I just not see them?) for the two default routes; so does (3) not apply? Straight to (4)? Or what command would allow me to see the metrics on OS X (I checked netstat -rn and route)? –  scherand Jul 2 '12 at 5:49
    
I am not on Linux, but from the manual I doubt that ping -I names an interface in the sense of your question, since -I can be "numeric IP address or name of device", thus ignoring the question of duplicate IPs. The only documented syntax I have found is included in my answer, and as I said I don't know to what degree it is implemented. Interface naming seems to be a gray zone only partially treated. Linux system calls can surely accept interface names, but it seems that not all applications fully implement a syntax for them. –  harrymc Jul 2 '12 at 7:44

Theoretically speaking, there should always be only 1 default route entry, because the idea of default route is that if routing algorithm cannot find route to a given IP address then it always send it to the gateway specified in the default route, which in your case is 192.168.1.1. Although I know UNIX/OS X both let you add multiple default routes. Specially in case of pptp VPN you might see two default entries. Which entry gets used is just OS implementation dependent. I have seen both UNIX/OS X always use first entry, but since its not a standard it might differ.

On a side note, please accept the the answer if you think it is correct, if you want people to respond to you

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.