Mar 192008
 

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.

  15 Responses to “How to add a Static Route (persistent) in Sun Solaris”

  1. I found this page really helpful and this helped me alot ..

    thanks

  2. Good stuff. Really helpful.

  3. I found that if you happen to be using a system with kernel path 118833-36 (S10 update 3?) or later, you can now use the -p argument to force the route to remain across reboots. Took them long enough. Sheesh!

    http://sunsolve.sun.com/search/document.do?assetkey=1-61-229381-1

  4. Good keep it up

  5. Awesome site. Thank you…

  6. route -p add 10.0.0.0/24 192.168.0.1

    man route

    -p is now the way to edit /etc/inet/static_routes

  7. Thanks a lot, it’s very helpful

  8. obsolete.
    check route -p

  9. We can also give the route entry in /etc/defaultrouter so that this is called after reboot, no need of any specific startup scripts.

  10. Take care -p is only availiable since Solaris 10.
    So the info is still valid for older versions!!

  11. This is very useful stuff..Please let me know haw to add a swap file on solaris when it’s start up..

  12. Darned if I can understand Solaris route command. I have a server with 4 ethenet ports e1000g0-g1000g3.

    I connected the lan over gateway1 to port0.
    route add 156.xxx.xxx.128 xxx.xxx.xxx.144 Works. I can ping servers on then vlan.

    I connected the lan over gateway2 to port1.
    route add 156.xxx.xxx.1 xxx.xxx.xxx.145 Does not work. Tries to go over 144.

    I connected port 3 to a tape drive (192.168.0.102) using port 3 (192.168.0.100). works. no entry in table.

    I try adding port 4 (192.168.1.1) to hub and server 192.168.1,2 to hub (non-managed).

    route add 192.168.1.2 192.168.1.1

    Does NOT work! It tries to connect over 156.xxx.xxx.144. But I never told it to! This is not in the table.

    It is supposed to connect 192.168.1.2 using 192.168.1.1, but it does not.

    What is going on here. Why doesn’t it do what I told it to?

  13. Thank you, it helped me a lot

  14. Appreciated. Well appreciated. This has helped me huge in major issue at my site. Thanks.

  15. I think the reason it won’t work is because you are using port 4 and you only have 4 0-3 and you haven’t used 2. Try that.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>