How do I make certain web addresses use a specific network adapter on Mac OS X?

I have two Internet connections at work, my wired Ethernet connection (which is heavily filtered behind a firewall, can't connect to Apple Updates, etc.) and a wireless connection that is unfiltered. I use my wireless connection as my primary connection so that things generally work. However, I have some intranet resources that I need to access via the wired connection only. How can I set it up so that when I visit something like "intranet.mycompany.com" - it will automatically route to the wired network adapter?


Solution 1:

You need to add a route manually to cover all the corporate networks. Find the smallest net block that will cover all the corporate IP addresses. For example, the corporate net might be entirely within the range 172.16.22.XXX—172.16.25.XXX. Thus your net block would be 172.16.16.0/20:

/sbin/route add -net 172.16.16.0/20 -interface en0

Note that on my machine, en0 is the Ethernet, en1 is the AirPort.

I have a script which sets up a bunch of routes for my local situation which is a corporate network for all corporatey stuff (time sheets, leave applications, workplace health & safety reporting, etc), with WiFi for the useful stuff (Bing, O'Reilly Safari, etc). I still haven't figured out where I need to put this script to have Mac OS X automatically add the arcane routes I need when the interface comes up though.

Solution 2:

You can setup your Network Service Order to pass most traffic through Wi-fi or Ethernet.

This makes the preferred connection be whatever service you put at the top of the list. Unfortunately, if you want most information to go through Wi-fi except for very specific items, this won't do that. If the Ethernet connection uses a different IP network range than the Wi-fi then it will automatically pass the required resources through Ethernet.

So, let's say you have the wolfing network. Wi-fi: 192.168.1.0-192.168.1.255 Ethernet: 192.168.5.0-192.168.5.255

Any services you need to access that have a DNS record pointing to 192.168.5.x will automatically go through Ethernet, but your DNS query WILL still go to 192.168.1.x

Any other websites that you services you visit will go through Wi-fi if Wi-fi as at the top.

To change the service order go to System Preferences->Network. Click on the Action menu (the gear at the bottom of the Services list) and choose "Set Service Order" Then drag the service you want to have precedence to the top of the list.