Configure static IP on Ubuntu 16

by Daniel Pham
Published: Updated:

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
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
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
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.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.