How to setup a static IP on Ubuntu 16.04

I had a bizarre situation where for some reason my router refused to reserve an IP address for a virtual server. Now, this can be a bit of a ball ache as the network IP addresses are issued by DHCP which means at some point in time the IP address will change when the IP lease expires. This is not good if you happen to have a server running as it requires a static IP address so that other computers can find it on the network. There is a workaround for this though, and I tend to use this in addition to reserving the IP at the router.

To set a static IP you will need to terminal into your server (or PC) and type the following command.

ifconfig -a

This will provide you with the following information displayed as follows.

For clarity I have listed the key pieces of information that you will require. First, look for the network adaptor, it will read something like this: enp0s3 Alongside this, you will see a block of text.

The key pieces of information that you will require are. inet addr: mask: The other pieces of information you will require will the gateway address and the dns-name servers. The default gateway (gateway) address will be the router address. In most cases, it will be along the lines of but check your router just to make sure.

The final piece of information you will require will be the dns-name server address. The DNS is basically a phone book for the internet and keeps track of domain names and the IP address associated with a website. This will normally be provided through your ISP however you can also use public DNS from Google or open DNS.

Google public DNS IP addresses

The Google public DNS IP addresses (IPV4) are as follows:

Open DNS IP Addresses