Difference between revisions of "Leopard Static Routes"

From Secure Computing Wiki
Jump to: navigation, search
(New page: I found a little how-to over at [http://www.osxfaq.com OSXFAQ] on how to do a proper static route on OS X Leopard, which will persist through reboots. Please, go over [http://www.osxfaq.c...)
 
(added static routing page for leopard)
Line 3: Line 3:
 
To add a static route you need to issue a command like:
 
To add a static route you need to issue a command like:
  
sudo route -nv add -net 192.168 -interface en0
+
sudo route -nv add -net 192.168/16 -interface en0
  
To avoid having to do this everytime you reboot your system:
+
To avoid having to do this everytime you reboot your system, we need to build a custom startup script.  The Apple/OS X way to do this, is to put a script in /System/Library/StartupItems.  Let's build the framework first:
<pre>cd /System/Library/StartupItems
+
<pre># cd /System/Library/StartupItems
sudo cp -R NetworkExtensions NetworkLocal
+
# sudo mkdir StaticRoutes
cd NetworkLocal
+
# sudo chmod 0755 ./StaticRoutes
sudo mv NetworkExtensions NetworkLocal
+
# cd StaticRoutes
sudo vi NetworkLocal</pre>
+
# touch StaticRoutes && touch StartupParameters.plist
 
+
# chmod 0644 ./* && chmod o+x StaticRoutes
- replace the startup section with the comand above to get:
+
</pre>
  
 +
Now that the files are there, fill them with the following text:
 +
===Static Routes===
 
<pre>#!/bin/sh
 
<pre>#!/bin/sh
  
Line 25: Line 27:
 
{
 
{
 
ConsoleMessage "Loading Static Routes"
 
ConsoleMessage "Loading Static Routes"
route -nv add -net 192.168 -interface en0
+
 
 +
## Enter static routes here, one line at a time as follows:
 +
# route add <destination_network> <next_hop>  (man route for syntax)
 +
 
 
}
 
}
  
Line 40: Line 45:
 
RunService "$1"</pre>
 
RunService "$1"</pre>
  
sudo vi StartupParameters.plist
+
===StartupParameters.plist===
 
+
-- edit it to get
+
 
+
 
<pre>{
 
<pre>{
 
Description = "Static Routes";
 
Description = "Static Routes";
Line 50: Line 52:
 
OrderPreference = "None";
 
OrderPreference = "None";
 
}</pre>
 
}</pre>
 
cd Resources/English.lproj
 
sudo vi Localizable.strings
 
 
-- edit it to get:
 
 
<pre>(?xml version="1.0" encoding="UTF-8"?)
 
(!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd")
 
(plist version="0.9")
 
(dict>
 
(key>Loading Static Routes(/key)
 
(string>Loading Static Routes(/string)
 
(/dict)
 
(/plist)</pre>
 

Revision as of 23:31, 4 April 2008

I found a little how-to over at OSXFAQ on how to do a proper static route on OS X Leopard, which will persist through reboots. Please, go over there and read it, if you'd like. I've got a couple minor changes to make it a bit clearer as to what it does:

To add a static route you need to issue a command like:

sudo route -nv add -net 192.168/16 -interface en0

To avoid having to do this everytime you reboot your system, we need to build a custom startup script. The Apple/OS X way to do this, is to put a script in /System/Library/StartupItems. Let's build the framework first:

# cd /System/Library/StartupItems
# sudo mkdir StaticRoutes
# sudo chmod 0755 ./StaticRoutes
# cd StaticRoutes
# touch StaticRoutes && touch StartupParameters.plist
# chmod 0644 ./* && chmod o+x StaticRoutes

Now that the files are there, fill them with the following text:

Static Routes

#!/bin/sh

##
# Load local static routes
##

. /etc/rc.common

StartService ()
{
ConsoleMessage "Loading Static Routes"

## Enter static routes here, one line at a time as follows:
# route add <destination_network> <next_hop>  (man route for syntax)

}

StopService ()
{
return 0
}

RestartService ()
{
return 0
}

RunService "$1"

StartupParameters.plist

{
Description = "Static Routes";
Provides = ("StaticRoutes");
Requires = ("Network");
OrderPreference = "None";
}