static routes in MacOS X howto

Sometimes we need to add permanently static routes, we can do that in this way

cd /Library/StartupItems

vi AddRoutes


#!/bin/sh

# Set static routing tables

. /etc/rc.common

StartService ()
{
sleep 10
ConsoleMessage "Adding Static Routing Table"

sudo /sbin/route add -net 192.168.101.0 -netmask 255.255.255.0 -gateway 192.168.101.1
sudo /sbin/route add -net 192.168.102.0 -netmask 255.255.255.0 -gateway 192.168.102.1
}

StopService ()
{
return 0
}

StopService ()
{
return 0
}

RestartService ()
{
return 0
}

RunService "$1"

vi StartupParameters.plist

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

chmod 755 AddRoutes
chmod 755 StartupParameters.plist

Leave a Reply

Your email address will not be published. Required fields are marked *