How to configure DNS nameservers on Ubuntu 18.04
On most Linux distributions you configure DNS nameservers in
/etc/resolv.conf. However in recent versions of Ubuntu that changed with the introduction of Netplan.
Netplan is configured by editing YAML files located in
/etc/netplan/. The precise name of this file will depend on your system configuration. I’m using an Ubuntu droplet on Digital Ocean, and the file is called
Configure DNS nameservers
- Open the
.yamlconfiguration file in
/etc/netplanusing your favourite text editor.
- In the
ethernetssection locate the network adapter you want to change the nameservers on (e.g.
nameserverssection and list the addresses of the DNS nameservers you want to use, as shown in the example below:
1 2 3 4 5 6 7 8 9
network: version: 2 ethernets: eth0: nameservers: addresses: - 22.214.171.124 - 126.96.36.199 # additional configuration omitted
Save and close the Netplan configuration.
To test your new configuration run:
sudo netplan try
This will temporarily apply your new network configuration and automatically revert to the old one after 120 seconds. This lets you check your new configuration hasn’t broken everything. If you’re connected via SSH, and the connection hasn’t broken, then that’s a good sign. To accept the new configuration press
To check that your DNS server configuration has changed run:
sudo systemd-resolve --status
Scroll down until to find your network interface. You should see something similar to:
1 2 3 4 5 6 7 8
Link 2 (eth0) Current Scopes: DNS LLMNR setting: yes MulticastDNS setting: no DNSSEC setting: no DNSSEC supported: no DNS Servers: 188.8.131.52 184.108.40.206
A more thorough way to check you’re using DNS from the provider you’ve configured is to run a DNS query and get the IP address of the server that was used. An easy way to do this is to run the following DNS query:
nslookup -type=txt resolver.dnscrypt.info
txtrecord will contain the IP address of the resolver that was used. For me this returned:
resolver.dnscrypt.info text = "Resolver IP: 220.127.116.11"
who.islookup on this IP address reveals it belongs to Cloudflare, which suggests
18.104.22.168is indeed being used to resolve DNS queries.