mac osx override default route for address range by net mask

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
2 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like