What traffic uses an interface bound route (RTF_IFSCOPE flag)?
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!
Solution 1:
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).