# Permanent Static Route Mac Os X 10.4.0



## tiburm (Jan 24, 2006)

Hi friends, i want to know how I can put a static route in my system MAC OS X 10.4.0 when i restart my computer.

TXS


----------



## Giaguara (Jan 24, 2006)

Would these be of any help?

http://www.macosx.com/forums/archive/index.php/t-13926.html
http://forums.macosxhints.com/archive/index.php/t-33745.html

To add a static route e.g.:


```
sudo route -nv add -net 192.168 -interface en0
```

To avoid having to do this everytime you reboot:


```
cd /System/Library/StartupItems
sudo cp -R NetworkExtensions NetworkLocal
cd NetworkLocal
sudo mv NetworkExtensions NetworkLocal
sudo vi NetworkLocal
```

- replace the startup section with the comand above:


```
#!/bin/sh

##
# Load network kernel modules
##

. /etc/rc.common

StartService ()
{
ConsoleMessage "Loading Network Local"
route -nv add -net 192.168 -interface en0
}

StopService ()
{
return 0
}

RestartService ()
{
return 0
}

RunService "$1"
sudo vi StartupParameters.plist
```

-- edit it to get


```
{
Description = "Network Local";
Provides = ("NetworkLocal");
Requires = ("Network");
OrderPreference = "None";
}

cd Resources/English.lproj
sudo vi Localizable.strings
```

-- edit it to get:


```
(?xml version="1.0" encoding="UTF-8"?)
(!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd")
(plist version="0.9")
(dict>
(key>Loading Network Local(/key)
(string>Loading Network Local(/string)
(/dict)
(/plist)
```

You could also edit the Network startup file and add the single line but that could get replaced if system is upgraded.


----------



## roarkh (Apr 6, 2006)

First I would like to thank Giaguara for the previous post, it has helped me more than any other I could find in setting up a persistant static route on Tiger.

I did run into a few gotchas that may have to do with changes Apple has made with updates or just unknown differences in our installations so I thought I would post my method in the hopes that it might help someone else.

I am assuming that anyone digging this deep into the system has probably enabled the root user so everything that follows assumes that you have opened a Terminal and typed 'su' to become root. Of course be very careful whenever doing anything as root on your system.

The first problem I ran into was that there was no /System/Library/StartupItems/NetworkExtensions on my system so I did not start with a copy of something Apple provided as Giaguara did.

So here we go...


```
cd /Library/StartupItems
```

I believe that /Library/StartupItems is a more correct location for 3rd party (non Apple) startup scripts so I am putting mine there  instead of /System/Library/StartupItems.


```
mkdir AddRoutes
cd AddRoutes
```

Use your favorite editor (I recommend vi or nano) to create a file named "AddRoutes" containing the following being careful to replace the (in blue) "route" command with your route:


```
#!/bin/sh

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

. /etc/rc.common

StartService ()
{
        ConsoleMessage "Adding Static Routing Tables"
        [COLOR="Blue"]route add -net 192.168.3.0/24 192.168.0.180[/COLOR]
}

StopService ()
{
        return 0
}

RestartService ()
{
        return 0
}

RunService "$1"
```

Then, create the file "StartupParameters.plist" containing the following:


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

Now we set up the proper permissions:


```
chmod 755 AddRoutes StartupParameters.plist
```

That's it. The stuff in "Resources/English.lproj" appears to be unnecessary, at least this works fine on my system (10.4.5 running on an iMac G5).

Reboot your computer and your route should be active. You can verify with a 'netstat -r' command on the Terminal.

Roark Holz


----------



## osxis (Jun 13, 2006)

Thank you very much roarkh... I followed step by step the instructions you posted ... but it still doesn't work.
With the netstat -r command I can see the route added in the routing table but when I try to reach the ip or the net tracert doesn't reach it.
Instead if I disable the startupitem and digit in the terminal the route add command it works...
What am I doing wrong or what is the tip ?

I'm going mad with this ... please help me


----------



## roarkh (Jun 13, 2006)

I'm not sure why the route would not work if you can see it in the routing table.

I would definitely check the ownership and permissions on everything. Your mileage may vary but I have...


```
Roark-Holzs-iMac:/Library root# cd /Library
Roark-Holzs-iMac:/Library root# ls -l
--- Stuff Removed ---
 0 drwxr-xr-x     6 root    wheel     204 Apr  6 13:22 StartupItems
--- Stuff Removed ---


Roark-Holzs-iMac:/Library root# cd StartupItems
Roark-Holzs-iMac:/Library/StartupItems root# ls -l
drwxr-xr-x   4 root  wheel  136 Apr  6 12:50 AddRoutes


Roark-Holzs-iMac:/Library/StartupItems root# cd AddRoutes
Roark-Holzs-iMac:/Library/StartupItems/AddRoutes root# ls -l
-rwxr-xr-x   1 root  wheel  292 Apr  6 10:05 AddRoutes
-rwxr-xr-x   1 root  wheel  127 Apr  6 09:47 StartupParameters.plist


File contents...

Roark-Holzs-iMac:/Library/StartupItems/AddRoutes root# cat AddRoutes
#!/bin/sh

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

. /etc/rc.common

StartService ()
{
        ConsoleMessage "Adding Static Routing Tables"
        route add -net 192.168.3.0/24 192.168.0.180
}

StopService ()
{
        return 0
}

RestartService ()
{
        return 0
}

RunService "$1"


Roark-Holzs-iMac:/Library/StartupItems/AddRoutes root# cat StartupParameters.plist
{
        Description     = "Add static routing tables";
        Provides        = ("AddRoutes");
        Requires        = ("Network");
        OrderPreference = "None";
}
```

Is all of this similar to what you have?

Roark


----------



## osxis (Jun 15, 2006)

Yes everything is equal to that....
I solved it just adding sudo in front of route add and now it works ....

Someone suggested me an alternate method : use login item , but don't have a clue of how to do them.. do you have some hints about them ?


----------



## tiburm (Jun 28, 2006)

Hi Roarkh, I need help about the route. 

I make in /Library/Startupitems/Addroutes the two files Addroutes and StartupParameters.plist with the same data like the exemple. But when i restart my computer never happen, the static route is not there. In my file Addroutes I put:

StartService ()
{
Console Message "Adding Static Routing Tables"
route add -n 192.168.0.0 192.168.0.10 255.255.0.0
}

with the others parameters, to add my route.

I make the new folder Addroutes in /Library/System/Startupitems, and i see in /System/Library/Startupitems that i haved a folder with the name StaticRoutes with a similiar script.

So my question is:
Where i put Addroutes?
I need remove the folder StaticRoutes in System/Library/Startupitems?

TXS


----------



## andyhargreaves (Oct 30, 2006)

Hi

Sorry to revive old threads, but I have tried all the suggestions here and on the other linked threads, and I cannot get any persistent routes at all.  Has anyone any tips for making this work??  The routes I am adding do not show up in netstat -r after a reboot.  The line I am using in the StartupItems subfolder is 


```
sudo route -nv add -host 191.253.0.0 -netmask 255.255.0.0 -interface 192.157.10.241
```

I've also tried all variations with and without sudo, and with and without /sbin/route

Thanks

Andy


----------



## blindzero (Jan 21, 2007)

Hi all,

this thread is really helpful for my problem, but I have still a little "quirk" in my mind about one issue on my configuration.
I dont want the script to be executed when my system starts up, but only when a defined L2TP VPN connection is connected (on Linux I would do a ppp postscript), but I couldnt find the files to edit this.

Should I still write this script in system startup?

Thanks a lot in advance for your help.

Matthias


----------



## geebee75 (Sep 11, 2008)

And what's wrong with adding a line (or lines) to /etc/rc.local?

 root# cat /etc/rc.local 
route add -net 172.22.0.0 127.0.0.1

Done. No pain in the butt editing and screwing around with /Library/StartupItems, etc etc. One line in one file.


----------



## AlanPaterson (Nov 2, 2009)

Above solution (file /etc/rc.local). There is no such file on my system (Snow Leopard). Should I create it?

(Sorry. Mac/Unix beginner here)


----------



## compuguynum1 (Feb 2, 2011)

Here's what I have for my 'AddRoutes'~~~~~~~~
#!/bin/sh

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

. /etc/rc.common

StartService ()
{
        ConsoleMessage "Adding Static Routing Tables"
        route add -net 10.30.49.31/32 10.32.3.100
}

StopService ()
{
        return 0
}

RestartService ()
{
        return 0
}

RunService ()
{
		return 0
}


AND HERE's WHAT MY STARTUP PARAMETERS~~~~~~~~~~~~~~

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Description</key>
 <string>Adding routes for Copiers</string>
 <key>OrderPreference</key>
 <string>None</string>
 <key>Provides</key>
 <array>
 <string>AddRoutes</string>
 </array>
 <key>Uses</key>
 <array>
 <string>Network</string>
 </array>
</dict>
</plist>



For some reason the route won't add!! please help!~


----------



## Chuck Dam (Nov 19, 2014)

It dosen't work for Mac Os X *mavericks*


----------



## Cheryl (Nov 20, 2014)

If you checked the date of this thread, you should have noticed that it was written several years before Mavericks was released.


----------



## Chuck Dam (Nov 20, 2014)

Yes but for information route dont work on *mavericks. *But it still work on Yosemite....

And yes 2006 so.... lol !!


----------



## Elizabeth001 (Nov 22, 2014)

1,cd /System/Library/StartupItems/
2,midir AddRoutes
3,cd AddRoutes
4,vi AddRoutes
!/bin/sh
# Set up static routing tables
. /etc/rc.common
StartService ()
{
  ConsoleMessage "Adding Static Routing Tables"
  route add 192.168.0.0/16 172.16.254.254  #
StopService ()
{
  return 0
}
RestartService ()
{
  return 0
}
RunService "$1"
5,vi StartupParameters.plist
{
  Description  = "Add static routing tables";
  Provides  = ("AddRoutes");
  Requires  = ("Network");
  OrderPreference = "None";
}
6,chmod 755 *


----------

