To add a Static Route in Sun Solaris operating system, you can use the route command. This will dynamically update the Kernel IP Routing table. However, when a server is restarted, these routes will be lost. To prevent this from happening, add a startup script S76static-routes with all the route commands for the static route that needs to persist. This will ensure that the route gets added at boot time.
To use the route command,
Syntax:
# route add [net|host] <Addr> netmask <Mask> [GatewayAddr|-interface ] <metric>
Example:
Add a network
# route add net 10.10.10.0 netmask 255.255.255.0 192.168.1.1 1
same as
# route add 10.10.10.0/24 192.168.1.1 1
Add a host
# route add host 1.1.1.1 netmask 255.255.255.0 192.168.1.1 1
same as
# route add 1.1.1.1/24 192.168.1.1 1
To route the traffic through an interface instead of an IP Gateway
# route add 1.1.1.1/24 -interface hme0
To check that the roots are added to Kernel IP Routing table,
# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
——————– ——————– —– —– —— ———
192.168.1.0 192.168.1.1 U 1 273 hme0
224.0.0.0 192.168.1.1 U 1 0 hme0
default 192.168.1.1 UG 1 196
Static Routes at boot time
To make the routes available at boot time so the next time when the server reboots, the routes are still available. Add a startup script named as
/etc/rc2.d/S76static-routes
and add the required route commands as above.
Change the permissions for the file so that the file is executable by root.
# chmod 744 /etc/rc2.d/S76static-routes
This should help.
Have I missed something? Have I made a mistake? please let me know by leaving a comment!
if you have a destop with ip 172.19.6.50 to access using a port 7588 to a server with ip 10.1.3.56 on solaris operating system.{solaris 10)
how do go about opening the port.
What is a ‘starup script’?
Do you mean an empty text file, with the command,
route add net 10.10.10.0 netmask 255.255.255.0 192.168.1.1 1
for example, added in the first line?
How do you know, from the output of netstat -rn, what gateway to put in? What netmask to use?
Why is the file called /etc/rc2.d/S76static-routes? Does the S76 have significance? Is it always S76 or does the number change based upon the situation?
Why is there a hyphen there in the name? Other writeups have just S, a number, and the word ‘staticroutes’. Does it matter?
How do you test a static route to make sure it worked?
I cannot find any of this information on the web.
Unfortunately I cannot reboot the box I am on, so I have no way of knowing if this ‘permanent’ route will come back.
how to configure gateway in sun solaris 10 operating system, i configure the ip address with help of “ifconfig” command. pls help me!!
To add a gateway :
# route add default 192.168.100.123
# echo 192.168.100.123 > /etc/defaultrouter
Simply writing ‘route add’ etc., in a text file and save it as /etc/rc2.d/S76static-routes works fine for me
Thankzzzzzzzzzzzz a Lottttttttt
As of Solaris 10 the ‘-p’ permanent flag was added to ‘/usr/sbin/route’.
route -p add default w.x.y.z
Now your route is permanent and will persist across reboots. Using /etc/rc?.d scripts is a BAD idea because with SMF your routes may get added after a dependant service is started.
In Solaris 10, the static routes are kept in /etc/inet/static_routes, but that file is to be maintained by using the “-p” (persistant) switch to the “route” command.
What about assigning a route to a specific interface? I am using Solaris 10, and I’d like to specify that a specific host be routed through my bge1 interface.
I’ve tried several flavors of:
route add -host a.b.c.d -iface bge1
but each comes back w/ “bge1: bad value”.
How to route two ips which is in two different networks?