Add or delete static routes Apple MacOS X


To totally unlock this section you need to Log-in


Login

Well this is most of the time easy but useful when need and you can't remind the command you have to use to add a static route in a Mac OS X installation.

Open fist the terminal session. Use the following command:

sudo route -n add x.x.x.x/24 x.x.x.x  

You have to enter your password.

Add or delete static routes Apple MacOS X

To delete a route you have to use the following command:

sudo route -n delete x.x.x.x/24 x.x.x.x

Add or delete static routes Apple MacOS X

To view you route table on you Mac you use the following command:

netstat -nr

Add or delete static routes Apple MacOS X

Permanent Solution

Add a startup item (to avoid doing the above command every reboot):

cd /System/Library/StartupItems
mkdir AddRoutes
cd AddRoutes

Create a file called AddRoutes (Note: same as the folder name).

vi AddRoutes

-------------------------
#!/bin/sh # Set static routing tables . /etc/rc.common StartService () { if [ "${ADDROUTES:=-NO-}" = "-YES-" ]; then ConsoleMessage "Adding Static Routing Table" sudo route -nv add 10.0.0.0/8 10.16.3.254 fi } StopService () { return 0 } StopService () { return 0 } RestartService () { return 0 } RunService “$1″

Then create a file StartupParameters.plist:

{
Description = “Add static routing tables”;
Provides = (”AddRoutes”);
Requires = (”Network”);
OrderPreference = “None”;
}

Then change permissions:

chmod 755 AddRoutes StartupParameters.plist

Reboot your computer. Verify with netstat -nr.