Choose a different version or distribution
Introduction
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 (8.8.8.8, 8.8.4.4)
- OpenDNS (208.67.220.220, 208.67.222.222)
- Level3 (209.244.0.3, 209.244.0.4)
- Cloudflare (1.1.1.1 and 1.0.0.1)
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:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.121.199/24
gateway4: 192.168.121.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
```
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:
nameservers:
addresses: [208.67.220.220, 208.67.222.222]
Values should be ,
separated, and you can use more than 2 nameservers as well.
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:
Output
DNS Servers: 208.67.220.220
208.67.222.222
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 (8.8.8.8, 8.8.4.4) and Cloudflare DNS (1.1.1.1, 1.0.0.1).
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.
Conclusion
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.