There are two methods to assign network configuration to a device on the net. DHCP or static assignment. DHCP is normally set as default. Static configurations usually need IP addresses as well as DNS resolvers plus routing. In this tutorial, we will cover Linux static configuration on Ubuntu 16.04.
- Cloud VPS or Dedicated Server with Ubuntu 16.04 installed.
- You must be logged in via SSH as sudo or root user. This tutorial assumes that you are logged in as a sudo user.
Step 1: Log in using SSH
You must be logged in via SSH as sudo or root user. Please read this article for instructions if you don’t know how to connect.
Step 2: Find the active network interface
clear && echo $(ip -o -4 route get 18.104.22.168 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')
Step 3: Configure the network interface
In our example, our network interface is ens18 with the following network details:
IPv4 = 22.214.171.124 Netmask = 255.255.255.0 Gateway = 126.96.36.199 DNS 188.8.131.52, 184.108.40.206
Our article will use network interface ens18 and the server details described above. Your server details will not be the same as our article and your network interface name can be different then we use in our article. Use the network interface name you get from step 2.
Edit your network configuration file
sudo nano /etc/network/interfaces
It should be similairto this configuration
auto ens18 iface ens18 inet dhcp
Replace the above two lines to use statc IPv4 instead of DHCP
auto ens18 iface ens18 inet static address 220.127.116.11 netmask 255.255.255.0 gateway 18.104.22.168 dns-nameservers 22.214.171.124 126.96.36.199
Apply the changes
sudo systemctl restart networking.service
Congratulations, you have now configured a static IPv4 for your Ubuntu 16.04 Operating System. If you need to configure static IPv6 for your Ubuntu 16.04 use this article.
not clear. you say to remove dhcp line but you still have it in your example. Can you show an final version of the file?
Ahmet Bas says
We will update this article ASAP. In the meantime, you can use our other article which has a working static IPv4 configuration https://www.snel.com/support/how-to-add-ipv6-on-ubuntu-16-04/
Ahmet Bas says
Article is updated