route add in Linux

Route manipulates the kernel’s IP routing tables.  Its primary  use  is to  set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program.

When the add or del options  are  used,  route  modifies  the  routing tables. Without these options, route displays the current contents of the routing tables.

Add static route using “route add”:
# route add -net netmask gw dev eth0

If you want persistent static route, you need to edit /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface.

# vim /etc/sysconfig/network-scripts/route-eth0

Save and close the file. Restart networking:
# service network restart

Verify new routing table by,
# route –n or # netstat –nr


Post a Comment