วันอังคาร, มกราคม 24, 2555

Ubuntu: Add permanent static routes

To keep the Static Route persistent or you want to add the route entries to the network script files (not using the route command) then all you need to do is to edit the file


/etc/network/interfaces
and the static routes in the following format:

    up route add [-net|-host] <host/net>/<mask> gw <host/IP> dev <Interface>




sudo cat /etc/network/interfaces

The output should show something like this



# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).


# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto eth0
iface eth0 inet static
address 172.20.10.1
netmask 255.255.255.0
broadcast 172.20.10.255
gateway 172.20.10.254

# static route
up route add -net 172.20.11.0/16 gw 172.20.10.254 dev eth0


** updated 20120702
from: http://www.cyberciti.biz/faq/setting-up-an-network-interfaces-file/
Sample: 
You need to insert the dns as follows:

    dns-nameservers 192.168.3.45 192.168.8.10
    dns-search foo.org bar.com


For the change to /etc/network/interface to take effect. please restart the “networking” service as follows:

sudo /etc/init.d/networking restart

ref: http://www.ubuntugeek.com/howto-add-permanent-static-routes-in-ubuntu.html