18

To give a concrete example, how does OSX choose which of these default entries from netstat -nr to route to?

Destination        Gateway            Flags        Refs      Use   Netif Expire
0/1                10.10.99.100       UGSc            0        0    ppp0
default            192.168.1.1        UGSc            5        0     en0
default            192.168.1.1        UGScI           1        0     en1
default            192.0.2.1          UGScI         157        2    ppp0 

From what I have been able to tell OSX uses metrics on its interfaces rather than on its routing table entries. But by default all of those interface metrics are 0 so how does it choose? Last created interface?

I've seen some folks suggest its the order in the Network preferences, but in my case the ppp0 interface (from SonicWall NetExtender) isn't listed there.

There is some discussion in this thread, but no answer that I see.

  • Have you find out how to set route metric? – endryha Dec 1 '15 at 19:37
5

Most systems follows these rules when choosing which route to use:

  • Find the most specific ones (i.e. the ones with the longest matching prefix).
  • Choose the one with the highest priority.

On Linux (and, I think, on Windows) priority is determined by metric, but it is not the case on macOS as you correctly pointed out. Instead of assigning metrics to individual routes, macOS assigns priorities to interfaces. You can use networksetup -listnetworkserviceorder to view this order and networksetup -ordernetworkservices to change it.

Now, this route from your output makes me think that in your case specificity also plays its role:

Destination        Gateway            Flags        Refs      Use   Netif Expire
0/1                10.10.99.100       UGSc            0        0    ppp0

This route covers the bottom half of the address space and therefore I would expect to also find:

128.0/1            10.10.99.100       UGSc            0        0    ppp0

in your routing table. This is a standard trick VPN software uses to prioritise its routes over default: it adds two routes which together cover all IP addresses, but each of them is more specific than default, so they win.

  • On Linux, priority is only determined by metric for single routing table cases, however higher priority rules can override metric of routes from another tables with lower prio rule entry in multiple routing table cases. Also with dynamic routing, one has to consider the lowest administrative distance. – Moreaki Feb 3 at 21:25
14

Any routing table which has multiple default routes with equal metrics does load balancing. The case with a mac though is that it will select the first interface which is in the interface list. If you want to see and change the list, go to "open network preferences", here you will see a list of network interfaces like ethernet, airport, ppp through mobile or 3g, etc. Below the list, you will see an asterisk shaped option with a down arrow. Click this and set the "set service order". Here you can change preference of your particular interface.

http://www.sustworks.com/site/prod_ipnrx_help/html/AlternateRouteHelp.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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