The Domain Name System (DNS) translates text-based domain names to numeric IP addresses. By default, most networks are configured to work with DNS servers supplied by the internet service provider. However, users are free to change the DNS nameservers.
This tutorial will show you how to change DNS nameservers on your Ubuntu machine using GUI or the command line.
- Ubuntu 20.04 (both methods also work on Ubuntu 18.04 and later)
- Access to the terminal
- Sudo privileges
Change DNS Nameserver via GUI
Use Ubuntu Settings to complete all the steps to change DNS addresses via the graphical user interface.
1. Launch Settings and click the Network tab in the menu on the left.
2. Click the cogwheel next to the connection you wish to set up.
Note: To change the settings for a wireless connection, select the Wi-Fi tab, choose a wireless network and proceed with the steps below.
3. Go to the IPv4 tab.
4. Disable automatic DNS configuration by turning off the switch next to the DNS field.
5. Type new DNS addresses in the field. The example shows Google's public DNS nameservers.
6. Click Apply.
The system is now configured to work with the new DNS servers.
Note: If you wish to set up IPv6 nameservers, go to the IPv6 tab and enter them there. The IPv6 address format is different from IPv4. For example, Google’s IPv6 DNS servers are:
Change DNS Nameserver via Config File
If you do not use a GUI, change DNS settings with the command line Netplan tool.
1. Go to the Netplan directory:
2. List the directory contents with
ls to see the name of the yaml file containing network configuration.
Open the file in a text editor. Your file may have a different name.
sudo nano 01-network-manager.yaml
Ethernet connections are listed in the ethernets section of the file. If there are any wireless connections, you can find them in the wifis section. Netplan stores the current DNS configuration parameters in nameservers subsections of each section.
Replace the addresses located in the file with the DNS addresses you want to use. You can enter more than two addresses. Save the changes and exit.
Note: The file on your system may lack the entire
wifis section. In that case, add the lines that are missing, making sure you respect the indentation provided in the example.
3. Apply the changes you made in the config file:
sudo netplan apply
If the operation is successful, there is no output. To check if the system successfully applied the changes, type:
systemd-resolve --status | grep 'DNS Servers' -A2
The output lists your current DNS servers:
Why Change DNS Nameserver on Ubuntu?
In most cases, your default DNS settings offer optimal performance. However, there are scenarios in which you should consider switching to a third-party DNS provider:
- Large companies with better infrastructure are usually more capable of providing uninterrupted DNS service. If your ISP is unreliable and you experience frequent downtimes, switching the DNS provider may be the solution.
- Third-party DNS servers can be faster than those provided to you by your ISP.
Note: Since latency is the primary consideration for DNS, a fast third-party server located far away may provide inferior service to a slower one that is closer to you.
- Some DNS providers offer filters that prevent phishing sites from reaching your computer. The same mechanism is also used to block sensitive content on the internet. Businesses often employ this DNS feature.
- Internet Service Providers sometimes block content on the DNS level, so switching to another DNS nameserver may help you access some geo-restricted websites.
This tutorial showed you how to set your DNS nameservers on Ubuntu, either using a graphical user interface or the command line.
To learn more about DNS, read What Is a Domain Name System & How Does it Work?