HOWTO quickly add a route in Mac OSX

4 March 2012 — 19 Comments

Adding a route manually can be necessary sometimes. When on Linux, I know the command by head:

sudo route add -net gw

On the Mac the command is similar, but a bit different 🙂 Just as a note to myself and anyone else interested:

sudo route -n add -net

This sets up a route to the net through gateway First one on Linux, second one on Mac OSX.

19 responses to HOWTO quickly add a route in Mac OSX


    I have connected my Mac to a Linux box directly using a cable (no home router involved).
    In Mac, I am setting a static IP address to with subnet mask and in Linux with same mask. My Mac has two NICs (2nd one is connected to router and WWW). How can I add a route in Mac so all the traffic intended for the Linux box goes through first NIC? I am interested in waking the Linux machine up using something like:

    $ wakeonlan -i 00:AA:BB:XX:XX

    Is this routing possible?


    Hi Hamid,

    Since you have the Mac and the Linux box in the same subnet (10.10.11.x) and have a subnet of /24 you do not need a route to be able to talk to each other. The mac wil automatically use the correct interface due to the netmask being used.

    If you have a specific error message, please post it and I will have a look. From the info I have now I’d say this just works. The first thing that comes to mind when you’d encounter a problem is the cable connection. Did you use a cross-cable? Are the LEDs turned on?

    Good luck!


      My mac mini is connected to the web through wifi (192.168.17.x). I don’t have control over the wifi net. I started playing with a router and connected it to the wired interface en0. I have a hard time connecting to which is the routers default address. I set en0 manually to I tried adding a route, but no go. Can you help?


        Did you already solve this issue? It does sound like a routing or netmask issue. If you tell a little more I might be able to help.


    Hi Remi, I have the exact same basic question as Hamid although for a different purpose, i.e. How to route traffic destined for a specific ip through a specific interface when everything is on the same subnet. In my case I would like to use my mac’s wifi interface to connect to a network share as it is faster than using an ethernet cable for file transfers, but keep the rest of the traffic prioritised according to the order the interfaces are listed in Network system preferences.


      I forgot to mention that I would like to be able to fallback to the ethernet interface if the wifi interface is disabled, thanks.


        I figured that you can do this with an ip address using ‘sudo route add -host -interface en1’ but that doesn’t work as the network share is accessed using it’s hostname myshare.local. Trying to route add -host myshare.local does not seem to work as although netstat -r shows a single entry for assigned to en1, myshare.local only has an entry assigned to en0 😦


        Hi Leo,
        Connecting to the same network multiple times, with the same ip addressing is confusing the OS and might give mixed results. The quick and dirty way to solve this, is to add another ip address to your server (say and one to your wifi interface (say and have the two communicate using the network. That will assure the routing is correct. You can use the same interface cards and same wires. Just add these as alias ip addresses and you’ll be fine.


    Hi Remi,

    Nice of you to share your knowledge, I have had something that’s been a consistent problem along the lines of this post that I’m hoping you have a suggestion about.

    I have two networks:
    a gigabit ethernet video editing network on a 192.168.1.x network (direct network, no outside connection)
    our standard corporate network on 10.130.x.x.

    Two Mac Pro’s have the network service order setup with the corporate network interface first (en1:DHCP) and the media network second (en0: and If I don’t put them in this order the internet doesn’t seem to work.

    The media server is also a Mac Pro with the en0 ( and en1 ( similarly setup.

    About 40% of the time the Mac Pros would connect to the media network over the slower 10.130 network… we figured out that if we used a GUI app called WaterRoof we could inject an ipfw command into the Mac Pros that blocks any connection to the media server on the corporate network (

    This worked great for a while, then suddenly today, the video started playing choppy again and I ended up having to disable the media server’s en1 to the corporate network to force the connection over the 192.168 network. Don’t know how it found it’s away around the IP block (perhaps connecting by share name ?) but I was wondering if creating a route would be a better answer… could you show me the syntax for that…
    do I need to do it on the Mac Pros AND the media server? Do I need to save it in some file for it to be permanent?

    Any help would be HUGELY appreciated!



      Interesting case! You could indeed add a route, so that even the corporate ip address will be reachable over the gigabit network.

      Try this on the Mac PRO’s:
      sudo route -n add -net

      And reversed on the Media server:
      sudo route -n add -net 10.130.178.x/32
      sudo route -n add -net 10.130.178.y/32

      netstat -nr gives an overview of current routes.

      This should make the Media server’s corporate ip address reachable through the gigabit network and vice versa.

      To make routes persistent, take a look at this post:

      Hope this helps 🙂


    Hi, This only works until you reboot the machine. Then the route is lost.


    My office has restricted access to Internet sites such as Skype & Dropbox. I also have access to an unrestricted Wi-Fi.

    The laptop is connected to both access points. Now my problem is, when en0 (ethernet) is my preferred channel then blocked sites like Skype won’t work though I have an active Wi-Fi connection. If I change the preferred channel to en1 (Wi-Fi) then Skype works but I cannot browse any of the company Intranet sites.

    Why does the fallback to Wi-Fior visa versa does not work?

    Here are my routing table entries using command netstat -nr:

    $ netstat -nr
    Routing tables

    Destination Gateway Flags Refs Use Netif Expire
    default UGSc 23 0 en1
    default UGScI 0 0 en0
    default link#6 UCSI 1 0 en3
    default link#8 UCSI 1 0 en14
    127 UCS 0 0 lo0 UH 3 151425 lo0
    169.254/30 link#6 UC 0 0 en3
    169.254 link#11 UCS 3 0 en1
    169.254 link#5 UCSI 0 0 en0
    169.254 link#6 UCSI 1 0 en3
    169.254 link#8 UCSI 1 0 en14 36:bb:1f:5:b7:d6 UHLSW 1 498 en3 889 link#6 UCS 0 0 en3 link#8 UCS 0 0 en14 96:eb:cd:3:8f:e4 UHLSW 5 38380 en14 325 link#8 UCS 0 0 en14 link#11 UHRLSW 0 16 en1 link#11 UHRLSW 0 8 en1 0:26:b9:9e:c6:e3 UHLSW 0 0 en0 1193
    172.16.8/23 link#5 UCS 2 0 en0 link#5 UCS 1 0 en0 68:5:ca:10:18:5 UHLWIir 1 0 en0 1073 c:4d:e9:c3:51:8c UHLWI 0 0 en0 1190 link#5 UCS 1 0 en0 0:25:0:a4:fa:de UHLWI 0 1 lo0
    192.168.2 link#11 UCS 1 0 en1 link#11 UCS 2 0 en1 74:31:70:6f:c6:58 UHLWIir 26 224 en1 1160 44:d8:84:8:85:e2 UHLWI 0 0 en1 692 link#11 UCS 1 0 en1 0:23:6c:97:46:a3 UHLWI 0 1 lo0 1:0:5e:7f:ff:fa UHmLWI 0 5 en3 1:0:5e:7f:ff:fa UHmLWI 0 19 en14


    Hee Remi, dit bericht is het eerste zoekresultaat als je in Google op “mac route add” zoekt. Na drie jaar nog nuttig in ieder geval 🙂



    I need some help for make the route permanent on OS X Yosemite if possible.





    I need some help for make the route permanent on OS X ElCapitan.



    Thank you 🙂

Trackbacks and Pingbacks:

  1. Add or delete static routes Apple Mac OS X Mountain Lion | Just another IT blog - April 4, 2013

    […] Add or delete static routes Apple Mac OS X Mountain Lion […]

  2. Adding Routes on Mac OS 10.9.x | The Coding - June 20, 2014

    […] Quick sanity check: what is the syntax for route add in Mac OS 10.9? Well, according to at least one source the syntax is slightly different. In the add-route file the syntax for the Mac and Linux commands […]

  3. How To Add Route In Mac | Information - October 2, 2016

    […] HOWTO quickly add a route in Mac OSX « Remi Bergsma’s … – Jun 20, 2014  · 18 responses to HOWTO quickly add a route in Mac OSX hamid (@hamiid) 11 October 2012 at 10:20. Hi […]

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s