Sep 4, 2023 4 min read

How to Set DNS Nameservers on Ubuntu 18.04

Set DNS Nameservers on Ubuntu 18.04 with our step-by-step tutorial. DNS is vital as it translates domain names into IP addresses.

Set DNS Nameservers on Ubuntu 18.04
Table of Contents

Choose a different version or distribution


Before we begin talking about how to set DNS Nameserver on Ubuntu 18.04, let’s briefly understand - What is DNS?

Domain Name System (DNS) can be termed as one of the most integral parts of a web infrastructure which makes it possible to translate domain names into IP addresses, much like a phone book.

Each and every device connected to the internet is identified by an IP Address. Every time you type the name of the website that you want to visit, it translates it to the corresponding IP Address.

Following are some of the free and public DNS resolvers:

  • Google (,
  • OpenDNS (,
  • Level3 (,
  • Cloudflare ( and

In this tutorial, you will set the DNS nameserver on Ubuntu 18.04. We will also address a few FAQs on how to set DNS Nameservers on Ubuntu 18.04.

Setting DNS Nameserver on Ubuntu Server

Earlier, whenever there was a requirement to configure DNS resolver on Linux, you only had to open the /etc/resolv.conf file to edit the entries. Then simply save the file.

This file is still available, but now it is a symlink controlled by the systemd-resolved service, which can't be edited manually.

DNS name resolution is provided by systemd-resolved service to the applications and other local services. It can be configured with the help of Netplan.

Configuration files of Netplan are stored in the /etc/netplan directory. There is no fixed name for the file, it differs from one setup to another. Generally, the file either exists with the name 01-netcfg.yaml or 50-cloud-init.yaml. It can be completely different in your system.

Using these files you can configure the network interface, including the IP address, gateway, DNS nameservers, and much more.

1) Open the interface configuration file using the below command:

sudo nano /etc/netplan/01-netcfg.yaml

2) The file’s contents will be similar to the following:

  version: 2
  renderer: networkd
      dhcp4: no
          addresses: [,]

3) In case you want to use a different name server, simply change the IP addresses with your preferred DNS servers. If you want to use OpenDNS then change the address line as follows:

          addresses: [,]

Values should be , separated, and you can use more than 2 nameservers as well.

Note: Don't use TAB for indentation, also use proper indentation.

4) After that, save the file and exit.

sudo netplan apply

5) Netplay will generate the configuration file for the system-resolved service.

6) To verify if the DNS resolvers are set, use the following command:

systemd-resolve --status | grep 'DNS Servers' -A2

7) It will give a lot of data in the output, you will have the grep the "DNS Server" string. You will get the output as follows:


         DNS Servers:

Setting DNS Nameservers on Ubuntu Desktop

1) Open the settings window.

2) Click on the Wi-Fi tab if you are connected to the Wi-Fi, otherwise, if you are connected to a wired network, click on the Network tab.

3) Now, you will have to select the connection for which you want to set the DNS nameserver. Click on the cog icon to open the Network manager.

4) After that, select IPv4 settings tab.

5) You will have to disable the "Automatic" toggle switch and enter the DNS resolvers IP address, separated by a comma. Use the OpenDNS nameserver:

6) Now, click on Apply button to save the changes.

Changes will be reflected immediately, excluding the DNS entries that are cached by your system or application.

FAQs to Set DNS Nameservers on Ubuntu 18.04

How can I set DNS nameservers using /etc/netplan/*.yaml file? 

Netplan is the default network configuration utility. You can specify DNS nameservers under the nameservers section of the YAML file.

After making changes, do I need to restart any services? 

Yes, you need to restart the networking service using the command sudo systemctl restart networking.

How can I check if the DNS nameservers are set correctly? 

You can use the nmcli dev show command or check the /etc/resolv.conf file to verify the DNS nameservers.

Can I specify multiple DNS nameservers? 

Yes, you can specify multiple DNS nameservers by separating them with spaces or commas.

Are there any public DNS nameservers I can use? 

Yes, popular public DNS nameservers include Google DNS (, and Cloudflare DNS (,

Can I set DNS nameservers temporarily for a specific interface?

Yes, you can modify the /etc/resolv.conf file for temporary changes specific to an interface.

What should I do if the changes don't take effect? 

Make sure to check the syntax of the configuration file(s), restart the networking service, and verify that there are no conflicting network configuration settings.


We hope this detailed guide helped you understand how to set DNS Nameserver on Ubuntu 18.04.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.