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 10.0.0.0/8 192.168.1.1

This commands tells the TCP/IP stack to sent traffic with the destination 10.*.*.* via 192.168.1.1. 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 10.0.0.0/8 192.168.200.15
}

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)

Comments

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

This didn't work for me, but

This didn't work for me, but I found something that did. This is just in case others are looking for a solution.

http://chimac.net/2010/04/27/how-to-add-a-static-route-permanently-in-snow-leopard-or-10-6/

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]