Static Vs Dynamic routes
Static routes are added using the route command either by a script or by using command line. Dynamic routes are added by some routing daemon. Daemons that are responsible for adding dynamic routes that are currently bundled/supported with Solaris are /usr/sbin/in.routed (Routing Information Protocol(RIP)) and /usr/sbin/in.rdisc (Router Network Discovery Protocol).
Using command line
To add a non-persistent route we just simple use route add command without the option -p. Note that these routes gets flushed if you reboot the system. Below are 2 examples of adding a route (192.168.1.1) for the network 10.10.10.0/24
# route add 10.10.10.0 -netmask 255.255.255.0 192.168.1.1 # route add 10.10.10.0/24 192.168.1.1
To add a persistent route we need to use the -p parameter with the route command. In the following examples the network 10.10.10.0/24 network uses the gateway 192.168.1.1.
# route -p add 10.10.10.0 -netmask 255.255.255.0 192.168.1.1 # route -p add 10.10.10.0/24 192.168.1.1
To add a persistent default route (192.168.1.1) :
# route -p add default 192.168.1.1
To retrieve information about a specific route :
# route get default route to: default destination: default mask: default gateway: 192.168.1.1 interface: e1000g0 flags: [UP,GATEWAY,DONE,STATIC] recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire 0 0 0 0 0 0 1500 0
To display the complete routing table :
# netstat -nr Routing Table: IPv4 Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ---------- --------- 192.168.1.0 192.168.1.30 U 1 23 e1000g0 18.104.22.168 192.168.1.30 U 1 0 e1000g0 22.214.171.124 192.168.1.30 UG 1 0 127.0.0.1 127.0.0.1 UH 4 121 lo0
The various flags (in the Flags column) :
U – The interface is up. H – Host route. The destination is a system, not a network. G – The delivery system is another system (an indirect route). D – The entry was added dynamically by an ICMP redirect.
To see the persistent routes added in the system :
# route -p show persistent: route add 10.10.10.0/24 192.168.1.1
To delete a persistent route (persistently) :
# route -p delete 10.10.10.0/24 192.168.1.1
Using rc script
The above command line method will not work in solaris 8 and 9, also in some older patch versions of solaris 10. To overcome this we have another method. We can create a rc script in /etc/rc2.d, say with name S91routes. Add the route add command in this script :
# /usr/sbin/route add 10.10.10.0 -netmask 255.255.255.0 192.168.1.1
Now when the next time the system boots up this script would run and add the route specified in the script.
To change a route, we can use route change command ( to change default route from 192.168.1.1 to 10.10.10.1) :
# route change default 10.10.10.1
To continuously monitor any changes to the Routing table and route lookup misses we can use route monitor command :
# route monitor got message of size 124 RTM_DELETE: Delete Route: len 124, pid: 633, seq 1, errno 0, flags:[UP,GATEWAY,DONE,STATIC] locks: inits: sockaddrs: [DST,GATEWAY,NETMASK] 192.168.3.0 sys11ext 255.255.255.0
To flush (remove) the routing table of all gateway entries, use the route flush command.
# route flush default 192.168.1.1 done 10.10.10.0 10.10.10.1 done
To cause the routing table to flush before the remaining options are evaluated, use the flush option before using other options :
# route -f add 10.10.10.0/24 192.168.1.1
To add a route manually to the multicast address range of 224–239 :
# route add 224.0/4 `uname -n`
To add a default static route using the /etc/defaultrouter file, add the default router IP address to the file /etc/defaultrouter. A system that is configured with an /etc/defaultrouter file does not execute the in.routed daemon.
# echo "192.168.1.1" >> /etc/defaultrouter
We can also use the /etc/gateways file to add static routes. If the /etc/gateways file exists, the in.routed daemon reads the file when it starts. Now to add a static route (192.168.1.1) for network 192.168.1.0, edit the /etc/gateways file and add below entry
# cat /etc/gateways net 192.168.1.0 gateway 192.168.1.1