How to set DNS nameserver in Ubuntu Server 18.04

For years, whenever you need to configure a DNS nameserver in Linux, users will find /etc/resolv.conf. Some simple settings will help your computer reach out to the outside world:

For years, whenever you need to configure a DNS nameserver in Linux, users will find /etc/resolv.conf. Some simple settings will help your computer reach out to the outside world:

 nameserver 8.8.4.4 
nameserver 8.8.8.8

But, like everything else, technology is always growing. Developers are always trying to change the way people manage things for decades. This is true for open source technology.

That is the case of DNS on Ubuntu Server. Although the /etc/resolv.conf file still exists, it is no longer the place you configure your DNS nameserver. Network changes continue to be made public. But, to be fair, the DNS configuration is actually incomplete (at least not permanently) in resolv.conf files for quite some time. In fact, before Ubuntu 18.04, the DNS nameserver has been configured in / etc / network / interfaces. In this file, the following item will help you get out of your LAN:

 dns-addresses 8.8.4.4.8.8.8.8 

Log in to server 18.04 and find the file / etc / network / interfaces . However, you can configure all you want, but they won't work. Why? That's because Netplan, a new networking block for Ubuntu. Now, users can configure DNS nameserver via Netplan.

Why does Canonical make this change? According to official documents, the reason is: Netplan has been deployed to simplify complex network configurations, as well as solve some of the current limitations of ifupdown. Netplan provides a simple and beautiful yaml configuration format with support for many backend providers.

In other words, everything has been simplified (especially when considering the popularity of the .yaml format).

New configuration

Although many people don't like to change, switching to Netplan is definitely the right step. With this change, the user's network configuration is handled in a single location (each interface has its own configuration file). Configuration files are found in / etc / netplan. The file name will be in the form 01-netcfg.yaml. One of the most important aspects of this file is to be aligned consistently (otherwise they will not load). In these files, the user will configure all aspects of the network interface (including IP addresses, ports, DNS, etc.). For DNS configuration, this is done with two lines of code. For example, if you use Google's DNS server, enter the command like in the image below.

How to set DNS nameserver in Ubuntu Server 18.04 Picture 1

DNS servers are separated by commas. To keep things neat, you should combine the related servers together as shown in the image below.

How to set DNS nameserver in Ubuntu Server 18.04 Picture 2

Of course, you can also set all DNS server addresses on one line.

How to set DNS nameserver in Ubuntu Server 18.04 Picture 3

As long as they are separated by commas or even add spaces after each comma.

How to set DNS nameserver in Ubuntu Server 18.04 Picture 4

Now, everything is more neat and readable. Once you've made the configuration changes, save and close the file, then enter the following command:

 sudo netplan apply 

The configuration will be read and will be valid, as long as it is in the appropriate format. If something goes wrong, you can add the debug switch as follows:

 sudo netplan --debug apply 

The above command will provide all the necessary output to troubleshoot the network configuration.

How to set DNS nameserver in Ubuntu Server 18.04 Picture 5

Whether you like it or not, this is currently the Ubuntu network configured. Make sure you are catching up with new changes in the Ubuntu world, otherwise you will be increasingly frustrated about why your network is constantly experiencing problems. Netplan is here to make things easier.

Good luck!

See more:

  1. How to configure DNS Server on Ubuntu Server 11.04
  2. Instructions for installing Ubuntu Web Server on remote host
  3. Instructions for installing BIKA LIMS Inkosi on Ubuntu Server
4.8 ★ | 4 Vote | 👨 1270 Views
« PREV POST
NEXT POST »