Configure static IP on Ubuntu 16

SystemMen - In this article, I will guide you through the static IP configuration on Ubuntu server 16. Using IP is a common requirement when you build your system, you need to manage your IP closely and clearly.

Check current configuration

You open the ssh window to Ubuntu machine, type the following command to check if the server is currently configured DHCP or static IP configuration. For example, my server has two interfaces, enp0s3 and enp0s8. I want to implement on enp0s8.

cat /etc/network/interfaces | grep enp0s8
configure-static-ip-on-ubuntu-16-01 Configure static IP on Ubuntu 16
Check current configuration.

As you can see in the image above, the interface is currently configured to IP through DHCP.

Set static IP for the interface

To set the static IP for the enp0s8 interface, type the following command to open the configuration file:

nano /etc/network/interfaces

Type the following if you are a regular user:

sudo nano /etc/network/interfaces

The configuration file will open similar to the image below.

configure-static-ip-on-ubuntu-16-02 Configure static IP on Ubuntu 16
File configuration interface initially.

Now delete the following two lines in the file.

auto enp0s8
iface enp0s8 inet dhcp

Then, you copy the following code to the place just deleted 2 lines above.

auto enp0s8
iface enp0s8 inet static


  • the static IP assigned to the interface.
  • netmask used for interface, this is /24.
  • gateway.
  • declare IP of DNS server, here we use DNS google.
configure-static-ip-on-ubuntu-16-03 Configure static IP on Ubuntu 16
Add static IP setup code.

After you finish adding, press Ctrl + X -> press y -> press Enter. This will save the file.

Next you type the following command to flush the old IP, you must be careful at this step. If you were previously ssh over the old IP, after you run this command, you will be disconnected from ssh.

sudo ip addr flush enp0s8

Then, you run the command to restart the network service so that the interface can receive the new IP.

sudo systemctl restart networking.service

Now you can check the new IP:

ip a


With this tutorial, you were able to completely configure a static IP for a server running Ubuntu server 16.

«« »»