Mac OS X – network interface preference defined by host domain

ethernetNetworkwifi

There are two network interfaces on my Macbook: an ethernet LAN and Wi-Fi, which are both DHCP-configured (albeit separately).

I only need to access a limited number of hosts through my Ethernet network, and want every other request to be routed through Wi-Fi. Those 'Ethernet' hosts can mostly be recognised by their domain mask which is *.foobar.com, but there are also a few exception which domain is different (but they can be identified by their exact IPs).

What would be the best way for me to organise it? I am thinking giving my Wi-Fi the top priority (by dragging it to the top in 'System Settings / Network' list), and then creating a routing rule like this:

route add -host 192.168.10.13 -interface en0

Is that a right approach? If so, what is the equivalent command that I can use to define en0 as a default route by domain mask (*.foobar.com) rather than by exact IP?

Best Answer

As has been pointed out in the comments, using DNS names for traffic distribution isn't possible (in your scenario). You need to provide local routing as desired and this needs to use IP addresses or subnets.

What you can do is set up the default gateway on the wi-fi NIC or lower the metric for wi-fi - if you want to stick to the all-DHCP setup you'll need to change this on the DHCP server. This takes care of using wi-fi as default network connection.

Then, you set up specific, local routes for the "Ethernet services'" IP addresses that have lower metrics for the Ethernet NIC with route add.