Add a permanent static route to Mac OS X

As a reminder for myself, but likely useful for you! If you are in a situation where you'd like to add a static route to you Mac OS X machine, you could issue:

$ sudo route add

This commands tells the TCP/IP stack to sent traffic with the destination 10.*.*.* via But, this command is only active after issuing it and before the next reboot. To "save" this command, make it permanent, you can take these simple steps.
$ sudo mkdir /Library/StartupItems/AddRoute
# cd /Library/StartupItems/AddRoute
$ echo "{
        Description     = \"Add static routing tables\";
        Provides        = (\"AddRoutes\");
        Requires        = (\"Network\");
        OrderPreference = \"None\";
}" > StartupParameters.plist
$ echo "#!/bin/sh

# Set up static routing tables
# Roark Holz, Thursday, April 6, 2006

. /etc/rc.common

StartService ()
        ConsoleMessage "Adding Static Routing Tables"
sudo route add

StopService ()
        return 0

RestartService ()
        return 0

RunService "$1"" > AddRoutes
$ sudo chmod 755 AddRoutes

Now you should be prepared. After a reboot, the route will be visible. (netstat -rnf inet)


Add the pertinent and

Add the pertinent and constant paper of the right and enduring the material is ensured for the paper write service the motion is included for the final and finesse.

Why sudo? The command you are

Why sudo?

The command you are using to add the route is:

sudo route add

But presumably, this bash script is already running as root. So what's the point in running it through sudo?

Yes, I agree. This is such a

Yes, I agree. This is such a useful idea now. - Mark Zokle

That didn't work for me. I

That didn't work for me. I also have something that works but I forget the URL. buy facebook likes

Use this method, it is

Use this method, it is better:

First, check the network services on your computer with the network setup command:

[email protected]:/dev$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Display Ethernet
Ethernet Pantalla Trabajo
Display FireWire
Bluetooth PAN
Thunderbolt Bridge
[email protected]:/dev$

Then, identify the device to which you want to add the static routes. In my case it is "Ethernet Pantalla Trabajo".

[email protected]:/dev$ networksetup -getinfo "Ethernet Pantalla Trabajo"
Manual Configuration
IP address:
Subnet mask:
Router: (null)
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Ethernet Address: 0c:4d:e9:xx:xx:xx

In my case, the device is configured in manual and without any gateway. I have my gateway pointing to a wifi network that gives me internet access, and I want to route all the private address space to this interface. So I add the following command:

sudo networksetup -setadditionalroutes "Ethernet Pantalla Trabajo"

Notice that you have to add all the routes on the same command. If you use three separate ones, every time you set the command, it will remove the previous configuration, so you will be setting one route and remove other.

After that, you can check that everything is ok with this command:

[email protected]:/dev$ sudo networksetup -getadditionalroutes "Ethernet Pantalla Trabajo"
[email protected]:/dev$

Finally, you could check with netstat -rn that the routers are there:

[email protected]:/dev$ netstat -rn | grep 10.1.36
10 UGSc 1 0 en8
10.1.36/22 link#14 UCS 15 0 en8 0:0:c:7:ac:1 UHLWIi 3 0 en8 1152 link#14 UCS 1 0 en8
172.16/12 UGSc 2 0 en8
192.168.0/16 UGSc 1 0 en8

The better point is that those routes will be "attached" to the network interface forever. I mean, if you unplug the cable, the routes will disappear, if you plug the cable again, the routes will appear. That's perfect because if it doesn't work this way, you could have problems with routes while you are not at your usual location.

I hope it could be interesting for someone, it has saved me :)

The method posted here could be valid, but in my case, I work in an office with a thunderbolt display on my desk and a macbook air. Every time I take my mac away from the display, with the method posted here, I will have to reboot the mac to get the routes configured again. With the method I shared, I can move around with the mac, and when I return to my desk and I plug the computer to the screen, the routes are configured again :)

Also, I have a secondary thunderbolt display at home. When I connect my mac to my home's thunderbolt display, the routes are NOT configured, because it is a different network interface, and this is fantastic because I don't need these routes at home or when I am connected only to the wifi network.

I hope you could find this interesting.

Best regards!


Nice - works well for me too.

Nice - works well for me too. Thanks.

nice! It's very useful.

nice! It's very useful.

in Snow leopard Server 10.6.3

in Snow leopard Server 10.6.3 I need to write the StartupParameters.plist as follows:
Description = "Add static routing tables";
Provides = ("AddRoutes");
Requires = ("Network");
OrderPreference = "None";

also sudo chmod 755 StartupParameters.plist

- there is also an

- there is also an inconsistency between "AddRoute" and "AddRoutes"

doesn't work for several

doesn't work for several reasons.

- the first echo fails because regular user can't create file in directory owned by root

- the second echo fails for the same reason, plus also your attempt at nesting double quotes fails

- even after compensating for these problems, config fails on 10.4.11, simply doesn't work

thanks anyway

About Consultancy Articles Contact

References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]