Set A Static IP On Ubuntu

Posted on Tuesday December 24, 2013 / by Eric Potvin

This article will guide you on how to set a static IP address on Ubuntu. This guide applies to all version of Ubuntu and Ubuntu Server.

Everything you need to setup is in the /etc/network/interfaces file. Use your favorite editor (for example VIM) to edit the file:

sudo vi /etc/network/interfaces

Then, you should see 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 dhcp

The key here is to change the last 2 lines. The last 2 lines tells the DHCP server to get an IP automatically. To configure properly your static IP, first run the ifconfig command to find out your current configuration:

/sbin/ifconfig

This will give you everything you need to configure properly your static IP. Now that you have everything, you will need to remove or comment the following lines of the /etc/network/interfaces:

#auto eth0
#iface eth0 inet dhcp

And add these lines with your own configuration:

auto eth0
iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-search google.com
    dns-nameservers 192.168.1.1

If you prefer to setup the nameserver somewhere else, you can also put the nameserver configuration in the /etc/resolvconf/resolv.conf.d/base file, by adding this line:

nameserver 192.168.1.XXX

Regenerate the resolv.conf:

sudo resolvconf -u

Remove the DHCP client:

sudo apt-get remove dhcp-client

Restart network service:

sudo /etc/init.d/networking restart

Done!