Subscribe Subscribe | Subscribe Comments RSS
Subscribe in Bloglines

Add to netvibes
Add to Google Reader or Homepage

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

9 Comments so far »

  1. by nigel dion, on March 19 2008 @ 5:57 am

     

    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.

  2. by jeff, on March 31 2008 @ 2:34 pm

     

    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.

  3. by amol, on April 7 2009 @ 9:23 am

     

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

  4. by ad, on May 12 2009 @ 6:40 am

     

    To add a gateway :

    # route add default 192.168.100.123
    # echo 192.168.100.123 > /etc/defaultrouter

  5. by Madhu, on May 21 2009 @ 2:04 am

     

    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. by Brad Bender, on August 17 2009 @ 4:23 pm

     

    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. by Chad, on August 29 2009 @ 5:39 pm

     

    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. by Nik, on November 6 2009 @ 9:11 pm

     

    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. by Sam Rajiev, on November 17 2011 @ 12:18 pm

     

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

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: