Add / Modify Static IP Address on Ubuntu 16.04

To add /modify the static IP address of your ubuntu installation follow the steps below:

Find out which interface is connected to the internet, issue the following:

[email protected]:~$ ifconfig

enp0s3    Link encap:Ethernet  HWaddr 08:00:27:1d:33:18
          inet addr:192.168.123.153  Bcast:192.168.123.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe1d:3318/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1444 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:158820 (158.8 KB)  TX bytes:10726 (10.7 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:11840 (11.8 KB)  TX bytes:11840 (11.8 KB)

In this case, the interface you’re looking for is enp0s3.

Currently this server has it’s interface set to get an IP address from the local DHCP server at the time of boot, we’re going to change that and set an IP of our liking.

Edit the file at: /etc/network/interfaces

Our file looks something like this:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp

The portion to look at are the last two lines, pretty self explanatory. To change this to a static IP setup remove the two and add the following with your own IP address:

auto enp0s3
iface enp0s3 inet static
address 192.168.10.241  #Change
netmask 255.255.255.0 #Change
gateway 192.168.10.1 #Change
dns-nameservers 208.67.222.222 8.8.8.8 #Change

To restart the network service:

sudo /etc/init.d/networking restart

That’s it, the new static IP should be active