Solaris UNIX Add Static Routes

Q. How do I add Static Routes under Solaris UNIX? My default gateway configured in /etc/defaultrouter, but what is the proper place to configure static routes for a Solaris UNIX server? Can you tell me exact configuration file name for a static routing?

A.. There are many ways to configure static routing under Solaris UNIX.

Task: Display current routing table

Use netstat command, enter:
# netstat -nr

Task: Delete a route

To delete a route, enter:
# route delete dest gateway
# route delete myhost myrouter

Method # 1: Set static routes using route command

Use route command to add static route on fly (dynamic modification of routing table), enter:
# route add dest gateway
# route add net netmask
# route add net
# route add host myhostname myrotername

The only drawback is static routes are not persistence i.e. routing will be deleted when Solaris box get rebooted.

Method # 2: Set static routing using /etc/gateways configuration for in.routed

The file /etc/gateways is act as configuration file for /usr/sbin/in.routed IPv4 network routing daemon. All you have to do is put static route per line using following format:

net Nname[/mask] gateway Gname metric value <passive | active | extern>

Open config file:
# vi /etc/gateways
Append following entries:
net gateway metric 1 passive
net gateway metric 1 active

You must one of these keywords must be present to indicate whether the gateway should be treated as passive or active, or whether the gateway is external to the scope of the RIP protocol. A passive gateway is not expected to exchange routing information, while gateways marked active should be willing to exchange RIP packets. The keywoard passive should be used if you want the entry to be permanent.The keyword active should be used if you want in.routed to occasionally query the gateway host, and delte the route if it becomes inactive. See in.routed man page for further details.

Save and close the file. You can set default router in /etc/defaultrouter file.

Method #3 : Managing routing using routeadm command

Solaris has routeadm command which is used to administer system-wide configuration for IP forwarding and routing. IP forwarding is the passing of IP packets from one network to another; IP routing is the use of a routing protocol to determine routes. You need to use /etc/defaultrouter to setup the default route and /etc/gateways to set static routing. To start the in.routed, enter:
# routeadm -u -e ipv4-routing
To view current routing configuration, enter:
# routeadm
To stop the in.routed daemon, enter:
# routeadm -u -d ipv4-routing

Method # 4: Old way – Create a init script

Login as root and type the command:
# cd /etc/rc2.d/
# touch S99static-routes
# chmod +x S99static-routes
# vi S99static-routes

Write a shell script and append static route using route command itself:
route add net netmask 1
route add net netmask

Save and close the file.

I recommend using method # 2 to create static routing under Solaris UNIX. See following man pages for further details:
$ man in.routed
$ man route
$ man gateways

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 13 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
13 comments… add one
  • Bogdan Jun 26, 2008 @ 18:31

    i dont know what author of this article was taking at the time of writing -> methods #2 and #3 have nothing to do with setting permanent/persistent static routes on solaris (as sbd eloquently put somewhere else they are only for setting/correcting dynamic routing protocols settings for in.routed(RIP and ICMP Router Discovery)… So that you dont loose as much time as I did because of this stupid article, read about ‘route -p’ command for setting persistent static routes (saves to /etc/inet/static_routes – dont edit directly)
    this applies to solaris 10u3 at least… (tested on u5)

  • Vireak Muth Jan 19, 2009 @ 13:59

    Good website for research

  • Brian Apr 8, 2009 @ 14:03

    good helpful information!

  • Giuseppe Sacco Apr 21, 2009 @ 17:48

    I found this site after trying using /etc/gateways on solaris 8. Solution #2 did not worked since in.routed will not be started when booting a system with a single nic.

  • arup Aug 18, 2009 @ 15:21

    useful site

  • M Harun-Ar-Rashid Aug 31, 2009 @ 6:20

    Very Helpful

  • Bulldog Dec 2, 2009 @ 14:07

    Thank you, it´s very helpful, but I´m rookie in this and I want to know, where I have to use my IP in method 2. I need set gateway to and my IP is, netmask is What will be format for method 2? I need to keep this settings after reboot system, thank you :-)

  • ranthoron Apr 9, 2010 @ 11:12

    the route command also has a -p switch, which causes changes made to become persistent…

  • aakash Dec 8, 2010 @ 6:52

    thanks for good practical .

  • AEG Jun 8, 2011 @ 1:50

    is there a way for one to be able to configure the a solaris 8 machine which has 4 NICs all connected to the same network to pass traffic being originated by them or directed to their IP to get it directly from the default gateway instead of using the “primary” interface of the machine with the highest priority or that appears first in the static routing table?

  • shrek Jul 27, 2011 @ 20:51

    really appreciate your help

  • Rajendraprasad Thota Aug 24, 2012 @ 10:52

    Very Helpful

  • shashank Feb 15, 2013 @ 14:03

    thanks very useful doc.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum