After installing Ubuntu, you might find the IP address has been configured to use a DHCP server and therefore is being assigned a dynamic IP address. In this post, we will configure Ubuntu Server 16.04 so that is uses a static IP address.
Configuring Ubuntu Server 16.04 to use a Static IP Address
In the following example, we will make the IP address static so that the server always starts with 192.168.1.33.
Open the network interfaces config file with your favorite text editor. In this post we will use vim.
sudo vim /etc/network/interfaces
Search for the line after the last comment which should say The primary network interface. The yellow highlighted text in the image below shows the line we need to edit.
Change the word dhcp to static and then add the following settings below it.
iface ens160 inet static
Note: The interface name might be different for you (ethX or ensX). You will also need to change the IP address and gateway to what matches your required setup.
Now restart the server using the following command to make the changes take effect.
Once the server reboots, you should now be able to connect using the new IP address (192.168.1.33) and it will keep this IP address during future restarts.