19 October 2010

Static Routes in Solaris

This tip may seem somewhat trivial as we all know that to retain static
routes in Solaris, you simply create an init script such as the following:

        adler [0] ls -l /etc/rc2.d/S76route
        -rwxr-xr-x   1 root     other        392 Mar 24  2009 /etc/rc2.d/S76route*
        adler [0] cat /etc/rc2.d/S76route
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net
        /usr/sbin/route add -net

What you might not know, is that in Solaris 10, Solaris now has a means
of retaining persistent static routes, complete with a new option (-p)
to 'route' and a config file.  In Solaris 10, the following 'route'
command would set a persistent route to be retained through reboots:

        adler [0] route -p add -net
        add net gateway
        add persistent net gateway

The above created route would still appear the same in a listing of the
routing table, however, you may notice that there is a secondary line
of output upon creating the route:

        add persistent net gateway

This simply means that the 'route' command updated config file
/etc/inet/static_routes.  By default, this file will not exist until
a static route is created via 'route -p ...' or you create it.  Before
getting to contents, the following are the ownership / permissions set
to the file by 'route':

        adler [0] ls -l /etc/inet/static_routes
        -rw-r--r--   1 root     root          45 Oct  6 13:35 /etc/inet/static_routes

And now, the contents, which are effectively the arguments to 'route add':

        adler [0] cat /etc/inet/static_routes
        # File generated by route(1M) - do not edit.

Yes, I know it says do not edit, though in checking out the source of
'route' via opensolaris.org, it doesn't appear that manual editing
is an issue.  Finally, Solaris has a native, standardized means of
configuring persistent static routes.

Additionally, to remove a static route, delete it from
/etc/inet/static_routes and remove via 'route' or simply use the following
'route' command:

        adler [0] route -p delete -net

see also:
    Static Routes in FreeBSD
    Static Routes in Linux

No comments: