Operating System - HP-UX
1826909 Members
3000 Online
109705 Solutions
New Discussion

Re: add static routes at startup ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

add static routes at startup ..

Hello
Does anyone have a script would add static routes at startup. I know how to enable it but I dont know how to write a config file. My understanding is that I need a config file in rc.config.d to add a script to add routes on startup. Does anyone have a config file or suggestions?

Richard
7 REPLIES 7
Angus Crome
Honored Contributor

Re: add static routes at startup ..

I don't have a script written, but if you take a look at /sbin/init.d/net (a link from /sbin/rc2.d/S900net to it as well), you should be able to use that as a template for entering the route commands you need. Don't enter them directly into that script though, as it gets overwritten during upgrades and some patches. You could just copy the script to say net2 and make some modifications. I would suggest cleaning out the redundant entries in it as apposed to the net script.
There are 10 types of people in the world, those who understand binary and those who don't - Author Unknown
Sridhar Bhaskarla
Honored Contributor
Solution

Re: add static routes at startup ..

Richard,

If you are going to use the IP of one of the interfaces for routing, then you can use the default /etc/rc.cofnig.d/netconf file itself.

Otherwise, you need to write a small script and put it under /sbin/init.d with proper links in /sbin/rc3.d file.

You also may want to create a control file in /etc/rc.config.d where you would define a variable that will be checked by the script in /sbin/init.d directory.

Following is the skeleton of the script. You can customize it according to your needs.

/etc/rc.config.d/statroute:

#Your comments
STATICROUTE=1

/etc/sbin/init.d/statroute:

#!/sbin/sh
#Your comments

PATH=$PATH:Your_additional_paths
export PATH

if [ -r /etc/rc.config.d/statroute ]
then
. /etc/rc.config.d/statroute
else
echo "/etc/rc.config.d/statroute file missing"
exit 1
fi

case $1 in

start_msg)
print "Adding the static routes"
exit 0
;;
start)
route add net your_destination your_ip
if [ $? != 0 ]
then
echo "Failed to add static route"
exit 1
fi
*)
print "Improper arguments to the script"
exit 1
esac

//End of File//

#ln -s /sbin/init.d/statroute /etc/rc.config.d/rc3.d/S9xxstatroute

We are not interested in stop sequence.

You need to check the syntax of the above script and add if you need anything.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: add static routes at startup ..

oops.. missed a small thing..We didnt' check for rc.config.d file.

....

start)

if [ $STATICROUTE = 1 ]
then
route add net your_destination your_ip
if [ $? != 0 ]
then
echo "Failed to add static route"
exit 1
fi
else
exit 2
fi

....
You may be disappointed if you fail, but you are doomed if you don't try
linuxfan
Honored Contributor

Re: add static routes at startup ..

Hi Richard,

The easiest thing to do is to modify the /etc/rc.config.d/netconf. You could do something like this

ROUTE_DESTINATION[0]=default
ROUTE_MASK[0]=""
ROUTE_GATEWAY[0]=xxx.xxx.xxx.254
ROUTE_COUNT[0]=1
ROUTE_ARGS[0]=""

ROUTE_DESTINATION[1]="net yyy.yyy.yyy"
ROUTE_MASK[1]=""
ROUTE_GATEWAY[1]=xxx.xxx.xxx.zz
ROUTE_COUNT[1]=1
ROUTE_ARGS[1]=""
Here xxx.xxx.xxx.254 is your default gateway
yyy.yyy.yyy is the network you want to setup a static route to
xxx.xxx.xxx.zz is the IP address you want to use to connect to the network yyy.yyy.yyy

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: add static routes at startup ..

Hi Richard,

I wrote a script for you (I took the template in /sbin/init.d and modified it). You just have to change the static_route configuration file to be placed in /etc/rc.config.d.

Once you copy the scripts, make sure you create the links in /sbin/rc2.d for startup and shutdown

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Magdi KAMAL
Respected Contributor

Re: add static routes at startup ..

Hi Richard,

For defining route on startup, you better configure your /etc/rc.config.d/netconf :

Entry :

ROUTE_GATEWAY[x]=ip

x : Is the instance number ( start at zero and for other instances you can increment one, two etc...)
ip : IP address for the default route gateway.

Magdi
Magdi KAMAL
Respected Contributor

Re: add static routes at startup ..

Hi again Richard,

Of course, the following :

ROUTE_DESTINATION[x]=default
ROUTE_MASK[x]=""
ROUTE_COUNT[x]=1
ROUTE_ARGS[x]=""

and for other gateway :
ROUTE_GATEWAY[y]=address1
ROUTE_DESTINATION[y]=address2
ROUTE_MASK[y]=""
ROUTE_COUNT[y]=1
ROUTE_ARGS[y]=""

Magdi