How to Change DNS Server on Ubuntu 20.04 [2 Easy Methods]

ubuntu dns settings

Want to make your online experience better on Ubuntu 20.04?

Understanding Ubuntu DNS settings is critical for all Linux users. Whether you aim to use Google’s popular 8.8.8.8 or 8.8.4.4 DNS, Cloudflare’s privacy-focused 1.1.1.1, or any other public DNS service, you should know how to find the current DNS information and change them if needed.

This guide will walk you through changing DNS nameservers on Ubuntu 20.04, ensuring a smoother and potentially faster internet connection. However, first, let’s discuss the need for setting DNS information on Ubuntu.

Table Of Contents

  1. Why Should You Set a Custom DNS on Ubuntu?
  2. How to Customize Ubuntu DNS Settings
    1. The Prerequisites
    2. Method #1: Change DNS Nameserver Information in the config File
    3. Method #2: Change DNS Nameserver From the GUI
  3. Conclusion
  4. FAQs

Why Should You Set a Custom DNS on Ubuntu?

In most cases, a system’s default DNS settings offer optimal performance. However, there are scenarios in which you should consider switching to a third-party DNS provider. In general, you can get the following benefits when you update Ubuntu DNS settings:

  • Speed: Some DNS servers are faster than others, leading to quicker domain name resolution because of lower latency.
  • Reliability: A reliable DNS server ensures consistent internet access.
  • Security and Privacy: Certain DNS providers offer enhanced security features and privacy protections.
  • Bypass Restrictions: Some DNS servers can help bypass regional restrictions and censorship.

How to Customize Ubuntu DNS Settings

Let’s explore how to set up the Ubuntu DNS server with the following two methods. Here’re the prerequisites:

The Prerequisites

Before we dive into customizing DNS Nameserver settings on Ubuntu 20.04, ensure that you meet the following prerequisites:

  • A system running Ubuntu 20.04.
  • An account with administrative rights.
  • Basic familiarity with the Linux command line interface (CLI).

Method #1: Change DNS Nameserver Information in the config File

You can quickly change the DNS server in the Ubuntu 20.04 environment by editing the device’s configuration file.

With the introduction of netplan in Ubuntu 18.04 and later versions, you have a robust tool for managing and editing network settings.

Here’s how you can change your DNS nameserver using netplan:

Step #1: Find the netplan Configuration Files

These files are typically located in the /etc/netplan/ directory. You can list them using the following command:

# ls /etc/netplan/

etc netplan

Step #2: Edit the Configuration File

Open the 01-netcfg.yaml file with a text editor like Nano or Vim.

For the demonstration, we’ll open it with Vim:

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

Find the relevant network interface section and add the new DNS server information:

netcfg yaml

Save and close the file.

Step #3: Activate Changes

Now run the following command to load the changes you made in the config file.

# sudo netplan apply

You might not see any indication of the success of the changes. You can confirm the changes by running the following command:

resolvectl status | grep "DNS Server" -A2

This command will display your current DNS server information.

  resolvers

Method #2Change DNS Nameserver From the GUI

Ubuntu allows you to change DNS nameserver information from the GUI. We recommend following these steps.

Step #1: Search ‘Network’ in Settings

Search for Network in the Settings menu. This will open the central location where you can manage all network-related settings.

Step #2: Select Your Network Connection

In the Network settings window, you’ll see a list of available network connections (wired, Wi-Fi, etc.).

Click on the connection you want to modify. If it’s a wired connection, it’s typically listed as “Wired” or “Ethernet.” Wireless connections are listed under “Wi-Fi.”

wndows network settings

Step #3: Access the DNS Settings

After selecting the connection, click the gear icon to access its settings.

Depending on your protocol, navigate to the IPv4 or IPv6 tab.

Step #4: Change DNS Settings

Start by toggling off the Automatic switch. This will allow you to set DNS servers manually.

Enter the DNS addresses you want to use in the provided field. You can enter multiple addresses separated by commas.

Note: You might also want to turn off the Automatic toggle for DHCP if setting a static IP address.

ethernet connection

Step #5: Apply Changes

Click Apply to save your changes.

You should disconnect and reconnect to your network for the changes to take effect.

To test the new DNS settings, you can open a terminal and use ping or nslookup commands to check domain resolution.

Conclusion

Setting up a custom DNS server on Ubuntu 20.04 is a straightforward process that can significantly improve your internet experience. Whether you choose the GUI method or the terminal approach, you can easily make this change. Enjoy the benefits of faster, more secure, and reliable internet browsing!

RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q: What is a DNS server, and why would I need to change it on Ubuntu 20.04?

A DNS server translates domain names into IP addresses. You should change it on Ubuntu 20.04 to improve internet speed security or to access region-restricted content.

Q: How can I find out my current DNS server on Ubuntu 20.04?

You can find out your current DNS server by running the command systemd-resolve –status in the terminal and looking for the “DNS Servers” entry.

Q: What are the steps to change the DNS server on Ubuntu 20.04?

Changing the DNS server on Ubuntu 20.04 includes editing the Netplan configuration files, specifying the new DNS server addresses, and applying the changes.

Q: Can I change the DNS server on Ubuntu 20.04 using the Network Manager GUI?

Yes, you can change the DNS server on Ubuntu 20.04 using the Network Manager GUI by accessing the network connection settings, selecting the appropriate connection, and entering the new DNS server addresses.

Q: How do I change the primary DNS server on Ubuntu 20.04 using the command line?

You can change the primary DNS server on Ubuntu 20.04 using the command line by editing the Netplan configuration files and specifying the new primary DNS server address.

Q: What are DNS records, and why are they essential when changing DNS servers on Ubuntu 20.04?

DNS records are essential for mapping domain names to IP addresses and other data. When changing DNS servers on Ubuntu 20.04, it’s crucial to ensure that DNS records are correctly updated to avoid disruptions in network services.

Q: Can I simultaneously set a static IP and change the DNS server on Ubuntu 20.04?

Yes, you can set a static IP and change the DNS server on Ubuntu 20.04 simultaneously by appropriately configuring the Netplan files to include both the static IP and the new DNS server addresses.

Q: How do I change the secondary DNS server on Ubuntu 20.04?

You can change the secondary DNS server on Ubuntu 20.04 by specifying the new secondary DNS server address in the Netplan configuration files and the primary DNS server address.

Q: Is changing the DNS server on Ubuntu 20.04 to use Cloudflare’s DNS resolver possible?

Yes, changing the DNS server on Ubuntu 20.04 to use Cloudflare’s DNS resolver by entering the Cloudflare DNS server addresses in the Netplan configuration files is possible.

Q: What precautions should I take before changing the DNS server on my Ubuntu 20.04 server?

Before changing the DNS server on your Ubuntu 20.04 server, it’s essential to have a backup of the current network configuration files and be aware of any potential network disruptions during the transition to the new DNS server.