Xi6.org

Tag: static route

Adding a static route in ubuntu linux

by on Mar.05, 2009, under linux/ubuntu

You may come across the circumstance where you have one ip subnet with a gateway ip on a different subnet.

Lets say for instance your static ip is 10.10.0.1 and you need to set the gateway as 9.9.0.1. After your initial setup of static ip, you may notice the destination is unreachable.

configure your static ip via command line

sudo nano /etc/netowork/interfaces

if you hapen to be using centos or fedora, you may use something similar to

system-config-network

(or)

setup

in ubuntu using the /etc/network/interfaces file

auto eth0
iface eth0 inet static
address 10.10.0.1
netmask 255.255.255.0
gateway 9.9.0.1

now while all looks right, you probably won’t be able to get online. You can restart your interface with

sudo /etc/init.d/network restart

if you add a custom route to the host and set the default gateway you should then be able to access something

sudo route add -host 9.9.0.1 eth0

sudo route add default gw 9.9.0.1

hopefully everything should be good to go! Make sure that your /etc/resolve.conf file has proper name servers for your isp.

nameserver 123.123.123.123

Now in order to make these changes persistant on startup/reboot you may add them to the /etc/network/interfaces file, but typically that has never worked for me across any distro.

What I do is add them to my rc.local file (which is executed after all other system modules are brought online).

sudo nano /etc/rc.d/rc.local

/sbin/route add -host 9.9.0.1 eth0
/sbin/route add default gw 9.9.0.1

This should help bring your network back online in case of power outage or reboot. Keep in mind that if you /etc/init.d/network restart you will likely have to manually add those routes by hand again. (no biggie).

To check your routing table just simply

route -n

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...