How to direct IP route through specific interface in OS X?

Solution 1:

Try:

route add -host 54.81.143.201 -interface en0

Solution 2:

As others indicated, this is actually 3 problems.

  1. Your wireless interface seems to be changing between en0, en3, and en5.

    On my MacBook Air, en0 is always wireless; Thunderbolt-to-Ethernet is always en3, and USB-to-Ethernet is always en5. But if you plug in an adapter to a different port on your Mac, then its NIC name changes. You need to solve this first. Make sure your wireless always has the same name. Otherwise when you enter the static route command, if there is no NIC plugged in to the en0 location, the command will (obviously) fail with an "address error" (physical address has no link).

    Likewise, make sure the adapter is always connecting to the same SSID. The gateway address obviously has to be valid for the subnet, and different WiFi networks will have different subnets. This can cause another type of error.

    You didn't specify if wireless is your only network connection. Given the above, I guess not...? This and virtual networking due to VMware or Parallels can cause additional complexities. (For example, if both connected networks use the same IP space... Virtual machines often are bridged and have their own IPs/routes/links...) Posting network topology would help.

  2. Once that's done, try either sudo route add -host 54.81.143.201 -iface en0 or sudo ipfw . If you're not sure of the adapter's name, you can specify its MAC address instead, like this: sudo route add -host 54.81.143.201 -link 14:10:9f:e7:fd:0a

    Related: https://discussions.apple.com/thread/5049994?searchText=policy%20route

  3. If you reboot, this may not persist. You'll need to handle that separately.

Solution 3:

sudo route -n add -net 54.81.143.201/32 192.168.15.1

Solution 4:

I was able to add a route across an interface by using the -link option to specify a MAC address.

route add -host 54.81.143.201 -link [mac addr of 192.168.15.1 on en0]

That will send traffic for 54.81.143.201 out the appropriate interface.

You do have two separate 192.168.15.* host addresses assigned, one to each interface, right? Else, you may send traffic out of either interface, but traffic will return on whichever source IP the packets have.