I'm on a mac and trying to route a particular address though a specific gateway on my wifi connection.

I'm using:

route add -host

Sometimes this will work, other times it wont. What I found is that the interface it chooses is different every time. It needs ot be en0 to work

netstat -nr output when it doesn't work:       UGHS            1       89     en5

This is when it does work: (note en0)       UGHS            0        1     en

Why am I doing this? Because our company has a proxy that HipChat doesn't work on. So I'm routing hipchat traffic through an open wifi network while still being on my works ethernet.


I also tried adding the entry using just the interface

route add -host -interface en0      78:31:c1:c7:52:74  UHS             0        2     en0

HipChat fails to connect.

EDIT 2: Someone asked for my whole routing table, here it is today. Note that is now bound to en3 and not en0

Destination        Gateway            Flags        Refs      Use   Netif Expire
default            UGSc           31        6     en3
10.7.90/24         link#4             UCS             4        0     en3          0:23:ac:3d:db:c2   UHLWIir        16        0     en3   1200         40:6c:8f:19:4a:bb  UHLWI           0        3     en3    946          UHS             0        0     lo0       UGHS            0        0     en3
127                UCS             0        0     lo0          UH              3      209     lo0
169.254            link#4             UCS             1        0     en3    0:23:ac:3d:db:c2   UHLSW           0        0     en3
  • Post the full routing table for the case where it doesn't work. Is reachable through en5? If so, why doesn't it work? If not, it's hard to see how that route got added. May 19, 2014 at 19:56
  • @DavidSchwartz, that's what is interesting to me. is not reachable through en5. The thing works when it correctly gets assigned to en0.
    – Sean256
    May 19, 2014 at 21:48
  • Show us the routing table or the configuration of en5. There must be some reason the route is getting installed that way, and that's probably the real problem. May 19, 2014 at 22:39
  • @DavidSchwartz It's not always en5, sometimes it's en3. I'm posting my whole routing table now.
    – Sean256
    May 20, 2014 at 16:05
  • In the routing table you showed, en3 is clearly correct. isn't reachable through any other interface. The only way to reach in that routing table is through the default route, right? (Bluntly, it sounds like you have no idea what you are doing. You seem to be surprised that the system is not doing the impossible.) May 20, 2014 at 16:58

10 Answers 10



route add -host -interface en0
  • 3
    This is what I get when I try that: route: bad address: en0
    – Sean256
    May 19, 2014 at 17:42
  • Sorry I don't have a Mac to test this. It looks like the syntax was wrong. I modified the answer. Please try again.
    – drkblog
    May 19, 2014 at 17:47
  • 2
    same thing sadly -> route: bad address: en0
    – Sean256
    May 19, 2014 at 19:18
  • Try again. This time I removed the gateway. Also, could you add the ifconfig output to your question to see IP configuration involved?
    – drkblog
    May 19, 2014 at 19:36
  • I just tried that (Actually I have before too) and it does add an entry to my table, it doesn't solve the issue. HipChat fails to connect. Here is the entry in the routing table when doing it that way -> 78:31:c1:c7:52:74 UHS 0 2 en0
    – Sean256
    May 19, 2014 at 21:53
sudo route -n add -net

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 -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 -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.


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

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

That will send traffic for 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.

  • So I tried what you suggested by using the mac addr, and oddly my routing table shows an entry for en3 and not en0 -> 00:1d.88.4a.21.da UGHS 0 0 en3
    – Sean256
    May 20, 2014 at 16:00
  • When you do an 'arp -an', what entries do you have...? May 20, 2014 at 19:04

This solution works on latest MacOS 10.12 (Sierra). Here's the Gist.


# NOTE: wifi network interface is: en1
TOADDR=`ifconfig en1 inet | sed -nl 's/\w*inet \([^ ]*\).*/\1/p'`
TO=`echo -n ${TOADDR//[[:space:]]}`

echo "ADDING ROUTE TO $1 VIA en1 (wi-fi): $TO"
route -n add -host $1 $wifi_router -ifp $wifi_address -ifa $TO -static

echo ""
route get $1

Use like this:

> sudo ./route_wifi.sh IP_ADDRESS

It assumes that wifi interface is: en1.

Don't forget to put correct values for wifi_router and wifi_address variables. Note wifi_address format, which is: network interface name':'interface mac address with '.' delimiters. Sure most of required information can be parsed out of ifconfig command output, but I'm just too lazy for that =)

  • Welcome to Superuser. Please try to contain most relevant information from the link in your post. Read more about it here. Aug 21, 2017 at 10:08

The OS X route command is documented here. The -ifscope parameter and its value allow you to specify an interface-bound route.

This is, however, not what you want. You need to fix your networks so their IP ranges are unique. Other than that, interface metrics (aka priorities) affect which interface is chosen from otherwise equally opportune option.


Here's how to translate the user-defined name 'Wi-Fi' into whatever device name (e.g. en0, en1, en9, ...) that MacOS has assigned at that time.

You can put these functions in a specific script, or just keep them in your .bash_profile.

function get_srvc_name ()
  cat <<EOF | scutil | \
    grep 'UserDefinedName' | \
    awk -F': ' '{print $2}'
show Setup:/Network/Service/$1

function get_srvc_ids ()
  cat <<EOF | scutil | \
    sed -nEe '
/ServiceOrder/ {
  /[0-9]+ :/ {
    s/ *[0-9]+ : ([0-9A-Z-]+) */\1/p
    b ids
show Setup:/Network/Global/IPv4

function get_srvc_id_by_name ()
  local srvc_ids=$(get_srvc_ids)

  for srvc_id in $srvc_ids
    local srvc_name=$(get_srvc_name "$srvc_id")
    if [[ "$srvc_name" == "$1" ]]
      echo $srvc_id

function get_int_name ()
  local srvc_id=$(get_srvc_id_by_name "$1")

  cat <<EOF | scutil | \
    sed -nEe '
    s/ *DeviceName : ([a-zA-Z0-9]+) */\1/p'
show Setup:/Network/Service/$srvc_id/Interface

Then just call get_int_name 'Wi-Fi' to get the assigned device name.

For example:

route add -host -interface $(get_int_name 'Wi-Fi')

On macos 14.2.1 (23C71), I added a subnet to my home vpn as follows:

sudo route -n add -net -iface ppp0

So the vendor server you're trying to talk to regarding the service "HipChat" you claim is In this case, I'd make a routing entry for to give it a bigger range. Maybe when using the software, you aren't always talking to this specific server, but a cluster of them on the same subnet Also, additionally, make sure your route metrics are correct when creating a new entry. If you create a route to Metric 20 En5, but also have a route to Metric 10 En0. The computer will ignore your new entry and continue routing traffic through the default route (via En0) because its more preferable. I just skimmered through this and wanted to point that out. Cheers!


You should try adding the NIC name:

route add -net netmask dev NicNameHere

This works for me in CentOS.

  • I get this -> route: bad address: dev
    – Sean256
    May 19, 2014 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .