Adding a permanent static route in Solaris
You can use the route
command to manually manipulate the network routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig(8)
utility.
Note: The route
command manipulates routes for the active system only. If you reboot the server the dynamic route will be lost. To prevent this from happening we can simply create a startup script in /etc/rc2.d directory.
Manually adding a route
Adding a route on the fly, we can issue the following:
route add [net|host] netmask [gateway|-interface]
Example #1
# route add -net 10.1.1.0 netmask 255.255.255.0 10.1.1.1
Example #2
# route add -net 10.1.1.0/24 10.1.1.1
Using the netstat
command we can display the current routing table:
# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 bge0 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
Setting the Default Route
Adding a default route using the route
command with the gw
sub-option. For example
# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 bge0 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo # route add default gw 10.1.1.1 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 bge0 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo 0.0.0.0 10.1.1.1 0.0.0.0 UG 0 0 0 bge0
To make route entries persistant across reboots we need to add the entries into a startup script. For example:
# vi /etc/rc2.d/S99static-routes #!/sbin/sh # # Add static routes # route add net 10.1.1.0 netmask 255.255.255.0 10.1.1.1 1 route add net 192.168.1.0 netmask 255.0.0.0 10.2.1.1 # chown root:root /etc/rc2.d/S99static-routes # chmod 0744 /etc/rc2.d/S99static-routes
To create a persistent defailt route across system reboots, add the hostname or IP address of the default routers into the file /etc/defaultrouter
. For example:
# vi /etc/defaultrouter 10.1.1.1