mac osx override default route for address range by net mask

2

1

On my mac I have two adapters, I'd like to use the WiFi as WAN and Ethernet as LAN by setting up some custom routing.

The service order is set to WiFi then Ethernet which in the routing table looks something like this...

netstat -nr

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           33        0     en0
default            10.1.1.1           UGScI           1        0     en2

Essentially, I want to add a route that's prioritized above the default for the address range of 10.0.0.0/8 to the existing gateway. In windows I'm able to do this by modifying the "metric" of the default routes and adding a new route with a lower metric but in OSX metrics are not associated to routes.

I've tried a few combinations of things and nothing seems to work

  1. route add 10.0.0.0/8 10.1.1.1
    • this is added after the default routes and is not picked up.
  2. route change 10.0.0.0/8 -interface en2
    • changed the gateway rather than the subnet mask and squashed the interface.
  3. route delete default
    • attempted to delete all defaults and add only the explicit set of routes
    • 0.0.0.0 is interpreted as default and get's reprioritized to top of list.

Maybe I'm fooling myself into thinking this should be easier than it actually is...

UPDATE: I was messing around with this for nearly three hours and not 5 minutes after I posted did it occur to me to check the DNS settings.

When I tried #1 above and pinged, this worked fine so DNS was the culprit. I had to manually add the DNS servers to the list of the other default adapter. Not completely sure why this is necessary on a mac as I assumed the DNS servers of all adapters would be searched. I'm not an expert, but this would make sense to me.

SOLUTION:

route add 10.0.0.0/8 10.1.1.1
networksetup -setdnsservers Wi-Fi 10.1.1.1 10.1.1.2

Phillip Fleischer

Posted 2014-09-19T13:40:17.257

Reputation: 121

2You should post your solution as an answer, not an edit to the question. – Barmar – 2014-09-19T19:32:43.763

Great. It solves my same problem. I want to get address xxx.yyy.com resolved by DNS server A, but problem is that address yyy.com is resolved also by DNS server B. For this it is necessary to define correct order of DNS servers. First has highest precedence. This is solution for "DNS config collision" when both DNS servers "can" return IP address, but only first one for whole address (with subnet included). – Tomas Hanus – 2017-02-21T16:13:02.290

No answers