Assign a static IP to Ubuntu

Assign a static IP to UbuntuWhen installing a new Ubuntu system it sets up the network cards to use DHCP by default.  I like to give my servers a static address.  So here are the instructions detailing how to assign a static IP to Ubuntu.  These instructions were written with Ubuntu 12.04 in mind, though will probably work on most other versions as well as many other Debian based distros.

First off get your self root access, click here for how to enable this if you haven’t done so already –

login as root

edit the network interface config file:

vi /etc/network/interfaces

change it from

# The primary network interface
auto eth0
iface eth0 inet DHCP

to look something like this: (though edit the IPs to match your own environment)

# The primary network interface
auto eth0
iface eth0 inet static

Save the file and then issue the following command to stop and restart your networking (you will be disconnected from your shell if you aren’t running locally):

ifdown eth0 ; ifup eth0

check your IP has changed using the following:

ifconfig eth0

You may need to edit your DNS settings once you have stopped using DHCP.   One issue I faced here was that Ubuntu reset /etc/resolv.conf after each reboot which is really annoying.  There are different ways of tackling this and the way that worked for me was to edit the resolvconf base file:

vi /etc/resolvconf.d/base

add your DNS servers and your local domain if you use one.  Your file should look something like this:

search mydomain.local

We can now restart resolveconf using this command:

/etc/init.d/resolvconf restart

Now you should be able to ping something like and get a reply.

Posted on October 10, 2012 at 23:44 by simon · Permalink
In: Linux · Tagged with: , , ,

Leave a Reply