• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Adding Static Routes On Various *NIX (Linux,AIX,HP-UX)

by admin

Static routes are generally required for traffic that must not, or should not, go through the default gateway. In this article we will discuss how to add static routes in various nix.

Scenario: Suppose if you want that all the traffic to network 172.168.102.0/24 should use 172.168.101.1 as gateway. This can be done by adding a static route in the kernel routing table as shown below.

Adding static route in Linux from the command line

# route add -net 172.168.102.0 netmask 255.255.255.0 gw 172.168.101.1 dev eth0

OR

# ip route add 172.168.102.0/24 via 172.168.101.1 dev eth0

Above Commands will make changes to the routing table temporary and not permanent. Use any of below mention command To check Routing tables in Linux:

# route -n 
# netstat -nr

Steps to make the static Route Persistent Across the reboot :

For RHEL/CentOS 5.X

Create a route file as shown below:

# vi /etc/sysconfig/network-scripts/route-eth0
172.168.102.0/24 via 172.168.101.1 dev eth0

Save and close the file and Restart network service:

# service network restart

For RHEL/CentOS 6.X

Create a route file as shown below:

# vi /etc/sysconfig/network-scripts/route-eth0
GATEWAY0= 172.168.101.1
NETMASK0=255.255.255.0
ADDRESS0= 172.168.102.0

Save and close the file and Restart network service:

# service network restart

Adding Static Routes in AIX

Step 1: Go to the SMITTY menu for routes.

Step 2: Select Type of route ‘net’ or ‘host’ (if default route then leave set to ‘net’).

Step 3: Enter the destination address.

Step 4: Enter the gateway address ( on the line that “* default GATEWAY Address”)

Step 5: If a ‘net’ or default route , enter the ‘Network Mask’ , if host do not set ‘Network Mask’

Step 6: Enter the network interface for this route. To select from the list arrow down to the ‘Network Interface’ line and hit[F4] or [ESC]+ [4] to display list of available interfaces.

Step 7: Hit [ENTER] TO APPLY . You should recieve a return status of “OK”

Step 8: To exit the smitty, type [F10] or [0].

Step 9: Verify that your routes have been configured.

# netstat -nr | grep UG

Adding Static Route in HP-UX

Step 1: Make a backup copy of ‘/etc/rc.config.d/netconf‘.

Step 2: Add a stanza to /etc/rc.config.d/netconf for the new route. Make sure you use a new array number for the stanza.

Example : Replace ‘nn’ with the next number in the list.

ROUTE_DESTINATION[nn]="IP-of-NewHost"
ROUTE_MASK[nn]=" "
ROUTE_GATEWAY[nn]="IP-of-Router"
ROUTE_COUNT[nn]=""
ROUTE_ARGS[nn]=""

Save and Close the file.

Step 3: Now run the below command to re-read the netconf file and add the route.

# /sbin/init.d/net start
Note: Run the above command with start option only because it will add new route without effecting existing network configuration.

Filed Under: AIX, Linux

Some more articles you might also be interested in …

  1. How to uninstall lammps package from Ubuntu
  2. What’s the difference between locate and find command in Linux
  3. How To Open A Port In CentOS / RHEL 7
  4. “WARNING: Duplicate VG name [vgname]” – error while running LVM commands
  5. How to Permanently set the ethtool settings in CentOS/RHEL 6
  6. faillog Command Examples in Linux
  7. How to Kill VNC Window Sessions in Linux
  8. host Command Examples in Linux
  9. lvresize command examples in Linux
  10. paste Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright