Nov 072007

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,


# route add [net|host] <Addr> netmask <Mask> [GatewayAddr|-interface ] <metric>


Add a network

# route add net netmask 1

same as

# route add 1

Add a host

# route add host netmask 1

same as

# route add 1

To route the traffic through an interface instead of an IP Gateway

# route add -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
——————– ——————– —– —– —— ———        U         1    273  hme0           U         1      0   hme0
default              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


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're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

  9 Responses to “HowTo: Add a Static Route (persistent) in Sun Solaris”

  1. if you have a destop with ip to access using a port 7588 to a server with ip on solaris operating system.{solaris 10)

    how do go about opening the port.

  2. What is a ‘starup script’?

    Do you mean an empty text file, with the command,

    route add net netmask 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.

  3. how to configure gateway in sun solaris 10 operating system, i configure the ip address with help of “ifconfig” command. pls help me!!

  4. To add a gateway :

    # route add default
    # echo > /etc/defaultrouter

  5. 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

  6. 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.

  7. 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.

  8. 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”.

  9. How to route two ips which is in two different networks?

 Leave a Reply



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=""> <s> <strike> <strong>