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

7,109

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.

Share:
7,109
JacobJ
Author by

JacobJ

Senior Principal software engineer at a Biomedical company. Author of the WPF Sound Visualization library (wpfsvl.codeplex.com)

Updated on September 18, 2022

Comments

  • JacobJ
    JacobJ over 1 year

    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?

  • Phillip Boushy
    Phillip Boushy almost 12 years
    I know that it is possible to add routing tables into OS X, since it is built on top of Unix, and I've heard of people doing it. But I do not know how. Try googling OpenBSD Routing Table CLI. This should tell you how to manage the routing tables through the command-line. If you can't find anything let me know, and I'll take a look.
  • geerlingguy
    geerlingguy almost 11 years
    Another note: if you boneheadedly screw up your routing table like I did (and can't access anything anymore), run route -n flush a few times, then switch your network location to something else and back to get back your normal routing information.
  • TraxusIV
    TraxusIV over 8 years
    I also have this issue, but need to do the opposite, and route only traffic to *.apple.com through wifi, and everything else through ethernet. Can the route tool be used for this as well?
  • Raphael Oliveira
    Raphael Oliveira about 6 years
    How do I do that bit "Find the smallest net block that will cover all the corporate IP addresses." please?
  • ManicDee
    ManicDee almost 6 years
    The net block is defined by the number of leading bits. In the example above the 172.16.16.0/20 net block means "the first 20 bits of the IP address must match 172.16.16" — the 20 means that you are "AND"ing the IP address with '11111111.11111111.11110000.0000000' to get the 20 leading bits and then comparing that result with '10101100.00010000.00010000.00000000'. If you know that there is a certain range for your corporate network, you need to find the longest string of binary digits that is common between the two.
  • DazChong
    DazChong over 4 years
    I cant thank you enough for this! I tried many other suggestion it didnt work. This saved me so much hassle to switch between interface while work in enterprise environment! :D