Static Routes

Solaris 10 Update 3 and Later
From Solaris 10 Update 3 these is in built support for storing static routes. To add a route persistently add a '-p' switch when specifying the route, this will make the route active and persistent across reboots.

'route -p add -net 192.168.24.0/24 10.10.10.1'

This will be saved in /etc/inet/static_routes eg:

-net 192.168.128.0/22 192.168.136.1 -net 192.168.138.0/24 192.168.136.1 -net 172.31.68.0/24 192.168.149.253 -net 172.31.69.0/24 192.168.149.253
 * 1) File generated by route(1M) - do not edit.

To delete a route and remove it from static_routes do:

'route -p delete -net ....'

Solaris 10 Update 2 and Earlier
Solaris 10u2 and earlier don't have support for static routes.

Using the old S99static trick doesn't work as the rc2 scripts won't run if the system doesn't reach milestone/multiuser which can happen if a service (such as rpcbind) fails to start.

As such a new SMF service is required.

Put this in :-

 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">



 

  















Then create the following (with modifications obv) at :-


 * 1) !/bin/sh


 * 1) RKstatic-routes


 * 1) To be called by the network/RKstatic-route SMF service

ACTION=${ACTION:-add}

setup_routes {

/usr/sbin/route $ACTION net 172.16.0.0 -netmask 255.255.0.0 10.25.0.216 /usr/sbin/route $ACTION net 172.18.0.0 -netmask 255.255.0.0 10.25.0.216 /usr/sbin/route $ACTION net 172.25.0.0 -netmask 255.255.0.0 10.25.0.216
 * 1) Route to NetBackup networks.

/usr/sbin/route $ACTION net 10.216.0.0 -netmask 255.255.0.0 10.25.0.216 /usr/sbin/route $ACTION net 10.218.0.0 -netmask 255.255.0.0 10.25.0.216 /usr/sbin/route $ACTION net 10.225.0.0 -netmask 255.255.0.0 10.25.0.216 }
 * 1) Route to SHMN networks.

case "$1" in   start)        echo "${ACTION}ing static routes"        setup_routes        ;;    stop) ACTION=delete echo "${ACTION}ing static routes" setup_routes ;;   *)        echo "Usage: $0 {start|stop}"        exit 1 esac

Then import the service:-

svccfg -v import /var/svc/manifest/network/RKstatic-routes.xml

Then you can enable and start the service with:-

svcadm enable network/RKstatic-routes

And remove the routes and disable the service with:-

svcadm disable network/RKstatic-routes

Enabling or disabling the routes with this method will persist across reboots.

Solaris < 10 (r3)
Adding static routes required soem fiddling:

I genral people just made a rc script to add the routes:

RC script to add routes
this tpyical script is not quite right... ($type $route and $gateway and only two values in the routes.conf) ln -s /etc/rc2.d/S95staticRoutes /etc/init.d/staticRoutes.sh cat staticRoutes.sh
 * 1) !/bin/sh

case "$1" in        start)                 test -f /etc/routes.conf || exit 0                 while read type route gateway                 do                         /usr/sbin/route add $type $route $gateway                 done < /etc/routes.conf                 ;;

stop)                test -f /etc/routes.conf || exit 0                 while read type route gateway                 do                         /usr/sbin/route delete $type $route $gateway                 done < /etc/routes.conf                 ;;         *) echo "Usage: /etc/init.d/routes { start | stop }" ;;

esac

routes.conf
172.19.42.0/24 172.19.41.4 172.19.43.0/24 172.19.41.4
 * 1) cat /etc/routes.conf

But to be clean on Solaris 8, 9 and 10 you can add your static routes at /etc/gateways like this:

net 100.100.100.0 gateway 192.1.243.1 metric 1