How to set DNS nameservers on Ubuntu 18.04 – The Domain Name System (DNS) is a central part of the web infrastructure, providing a way to translate domain names into IP addresses. You can think of DNS like an Internet phonebook.
Every device connected to the Internet is uniquely identified by its IP Address. When you type the name of the website you want to visit in your browser, the domain name must be translated into the appropriate IP Address. The operating system first checks its hosts file for the appropriate domain and if there are no entries for the domain, it will ask the DNS Nameserver configured to resolve domain name which is determined.
After the domain is resolved, the system caches the request and keeps records for the domain and the corresponding IP address.
DNS nameservers (resolvers) are servers used by other devices to perform DNS lookups for the requested domain.
Usually, DNS resolvers are provided by your ISP. However, these DNS nameservers may be slow or not updated regularly which can cause slow access when requesting a domain, resolver to the wrong IP address or sometimes you may not be able to visit the desired domain name at all.
There are many free public DNS resolutions that are fast, private and updated regularly.
Here are some of the most popular and fast public DNS nameservers:
- Google (
- Cloudflare (
- OpenDNS (
- Level3 (
You can also see a list of the best and fastest DNS nameservers that you can use for your internet network, check the following article → 5 Fastest and Secure Public DNS Server Choices.
In this guide, I will explain how to configure a DNS name server (resolver) on Ubuntu 18.04.
If you want to set up DNS Nameservers for all devices connected to your local network then the easiest and the recommended way is to make changes to the DNS Nameserver in router in your house.
How to set DNS nameservers on Ubuntu Desktop
For setting DNS nameservers on Linux computers Ubuntu 18.04 desktop very easy and requires no technical knowledge.
- Open the Settings window.
- If you are connected to a WiFi network click on the tab “Wi-FI“. If not, or if you have a wired connection click on the tab “Network“.
- Select the connection for which you want to set the DNS Nameserver and click the gear icon to open Network Manager.
- Select the tab menu IPv4.
- Disable the switch “Automatic”And enter the DNS Nameserver IP addresses, separated by commas. I prefer to use Google’s DNS Nameserver (
- Click the button “Apply“To save changes.
The changes will take effect immediately unless your DNS entries are cached by your system or application.
If you want to switch back to your old settings, open Network Manager, go to the IPv4 tab menu and activate the “Automatic” switch.
How to set DNS nameservers on an Ubuntu server
Going back in time, whenever you wanted to configure DNS Nameservers on Linux, you could just open the
/etc/resolv.conf, edit the entry, save the file, and you can continue. This file still exists but it is a symlink which is controlled by a system-resolved service and should not be edited manually.
systemd-resolved is a service that provides DNS nameservers for local services and applications and is configurable with Netplan, the default network management tool on Ubuntu 18.04.
Netplan configuration files are stored in a directory
/etc/netplan. You’ll probably find one or two YAML files in this directory. The file name may differ from setting to setting. Usually, the file is named
50-cloud-init.yaml but on your system, it might be different.
These files allow you to configure network interfaces, including IP address, gateways, DNS Nameservers, and so on.
To configure DNS Nameservers, open the interface configuration file with text editor You:
$ sudo nano /etc/netplan/01-netcfg.yaml
The contents of the file will look like this:
network: version: 2 renderer: networkd ethernets: ens3: dhcp4: no addresses: - 192.168.121.199/24 gateway4: 192.168.121.1 nameservers: addresses: [18.104.22.168, 22.214.171.124]
To configure DNS Nameservers, change the current IP address with the DNS server of your choice. For example, if you want to use a DNS server Cloudflare, You’re going to change the line
nameservers: addresses: [126.96.36.199, 188.8.131.52]
DNS servers must be separated by commas. You can also add more than two nameservers.
If the entry does not exist, add it below the interface name block. When editing Yaml files make sure you follow the YAML code indenting standards. If there is a syntax error in the configuration, Netplan will not be able to parse the file.
When finished save the file and apply the changes by:
$ sudo netplan apply
Netplan will generate configuration files for the services it resolves with
To verify that the new DNS Nameserver is set, run the following command:
$ systemd-resolve --status | grep 'DNS Servers' -A2
systemd-resolve -status print a lot of information. I use
grep to filter the string “DNS Server”. The output will look like this:
Output DNS Servers: 184.108.40.206 220.127.116.11
Netplan is the default network management tool on Ubuntu 18.04, replacing
/etc/network/interfaces the configuration file that was used to configure the network on Ubuntu version previous.