imported>DrOwl |
imported>DrOwl |
||
Line 143: | Line 143: | ||
===RC script to add routes=== |
===RC script to add routes=== |
||
this typical script is not quite right but it works verry well... ($type $route and $gateway and only two values in the routes.conf) |
this typical script is not quite right but it works verry well... ($type $route and $gateway and only two values in the routes.conf) |
||
ln -s /etc/rc2.d/ |
ln -s /etc/rc2.d/S70staticRoutes /etc/init.d/staticRoutes.sh |
||
cat staticRoutes.sh |
cat staticRoutes.sh |
||
#!/bin/sh |
#!/bin/sh |
Revision as of 09:10, 3 June 2008
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:
# File generated by route(1M) - do not edit. -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
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 /var/svc/manifest/network/RKstatic-routes.xml
:-
<?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- Static Route SMF Manefest To be replaced by official Sun mechanism in next solaris release --> <service_bundle type='manifest' name='RKstatic-routes'> <service name='network/RKstatic-routes' type='service' version='1'> <create_default_instance enabled='true' /> <single_instance/> <dependency name='network' grouping='require_any' restart_on='error' type='service'> <service_fmri value='svc:/network/service' /> </dependency> <exec_method type='method' name='start' exec='/lib/svc/method/RKstatic-routes start' timeout_seconds='60' /> <exec_method type='method' name='stop' exec='/lib/svc/method/RKstatic-routes stop' timeout_seconds='60' /> <property_group name='startd' type='framework'> <propval name='duration' type='astring' value='transient' /> </property_group> <stability value='Unstable' /> </service> </service_bundle>
Then create the following (with modifications obv) at /lib/svc/method/RKstatic-routes
:-
#!/bin/sh # RKstatic-routes # To be called by the network/RKstatic-route SMF service ACTION=${ACTION:-add} setup_routes () { #Route to networks. /usr/sbin/route $ACTION net 172.1.0.0 -netmask 255.255.0.0 10.1.0.0 /usr/sbin/route $ACTION net 172.2.0.0 -netmask 255.255.0.0 10.2.0.0 } 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 9 and earlier
Adding static routes required some fiddling:
In general people just made a rc script to add the routes:
RC script to add routes
this typical script is not quite right but it works verry well... ($type $route and $gateway and only two values in the routes.conf)
ln -s /etc/rc2.d/S70staticRoutes /etc/init.d/staticRoutes.sh cat staticRoutes.sh #!/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
#cat /etc/routes.conf 172.1.2.0/24 172.1.2.4 172.1.3.0/24 172.1.3.4
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