Static IP Address in Linux (Ubuntu)

Sometimes it can be useful to give a computer a static IP address. I was working on a Xen cluster and kept having to setup each machine with a static IP. I am posting this here to help me remember.

Edit this file.

sudo vim /etc/network/interfaces

Look for the lines that should say something like the following.

auto eth0
iface eth0 inet auto

This is presuming you only have one ethernet device in you computer. If you have more than one you may need to change eth1 or eth2 (or whatever), depending on which one you are using.

Take those lines and make it look something like this.

auto eth0
iface eth0 inet static
    address 192.168.0.150
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1

The ‘address’ is the static IP address that you choose. The rest of those could also be different depending on your network configuration and the IP address of your router (’gateway’ is usually the IP of your router).

After you get that setup like you want you can restart networking to test it out.

sudo /etc/init.d/networking restart

Then you can check that everything is correct by looking at the output of ifconfig.

ifconfig

It should show your device and the static IP address.

I was doing this on Ubuntu, but it should work for other distros as well.

Here is the reference link that helped me figure this out.

http://codesnippets.joyent.com/posts/show/319

Leave a Reply

{
}