Setup static IP for your Ubuntu Server

Good day my Linux Yogi’s,

I usually would expect as an Administrator that when you install a Server OS that you would have a step during the installation process to choose weather or not to configure either DHCP or Static IP for your server. We can only hope that this option will be available in the future. Therefore today I am going to illustrate for you how to set up your Ubuntu Server with a static IP address. 

Ubuntu Server will use out of the box DHCP to assign an available IP address to the system. In a few step I will show you how to change it to a static IP address. Let’s get started.

What we need to know for that is:

  • IP Address:
  • Subnet Mask
  • Gateway Address
  • DNS Server Address(es)
  • Search Domain

I am going to use IP address, subnet mask of, gateway address of, DNS Server of and search domain of “linuxmeditation.lan“.

The first thing I always do is to elevate the console to have root rights. Enter the following command:

sudo -s

enter your password and you have successfully elevated your console session and from now on you don’t have to use sudo in front of each command as long as you stay in this console session.

Let’s open up the file /etc/network/interfaces with your preferred editor. I use nano.

nano /etc/network/interfaces

you should see something similar like the following:

Default settings for interfaces
Default settings for interfaces

Now look under the section “# The primary network interface” in particular the last line. It shows dhcp which means its waiting to get an ip address assigned by the dhcp server. I will show you now how I always change it for my systems and then I will explain it.

auto enp0s3
iface enp0s3 inet static
dns-search linuxmeditation.lan

The second line “iface enp0s3 inet static” means that the interface enp0s3 will get a static IP address assigned.

The third line “address” means that we assign the address to this interface.

the fourth line “netmask” means that the IP address is in a full Class C network which means it can address directly IP addresses from to

The fifth line “gateway” means that it has to go here for addresses beyond this Class C network.

The sixth line determines the network

The seventh line “dns-nameservers” means that it should use first dns server to resolve names or IP addresses and if this one is not available it should use the secondary of You can add up to three dns server IP addresses separated by a simple space.

The eighth and last line “dns-search linuxmeditation.lan” means that it should try using/adding the domain suffix of “linuxmeditation.lan” if it is not given.

Now go ahead and save the file. Reboot the server and it should be responding on the newly set up IP address.
I also recommend that while you at it to edit the file /etc/hosts. It should look like the following: localhost ubuntuserver

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

The second line I always change to prevent for errors for example Apache is throwing an error message at you when you restart it that it was unable to determine the local servers full qualified domain name etc. Make it look like this and you avoid this issue all together as well as other issues: localhost ubuntuserver.linuxmeditation.lan ubuntuserver

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

In the case you like this article or think it was useful to you I would appreciate if you register and share this article. Please leave me a note of criticism or suggestion for future articles.

Until next time, Namaste my friends! 😀