How to Change DNS Nameservers on Ubuntu Easily

x32x01
  • by x32x01 ||
The Domain Name System (DNS) converts easy-to-read domain names like google.com into numeric IP addresses your computer can understand.

By default, Ubuntu uses the DNS servers provided by your Internet Service Provider (ISP). But you can change them anytime - to improve speed, privacy, or reliability. 🚀

This guide explains how to change DNS nameservers on Ubuntu using either the Graphical User Interface (GUI) or the command line.

🧩 Prerequisites​

Before starting, make sure you have:
  • Ubuntu 20.04 or later (works on 18.04 too)
  • Terminal access
  • Sudo privileges



🖥️ Change DNS Nameservers Using GUI​

If you prefer using the graphical interface, follow these simple steps:
  1. Open Settings → click Network on the left.
  2. Click the gear icon ⚙️ next to your network connection.
  3. Go to the IPv4 tab.
  4. Turn off Automatic DNS.
  5. Enter your preferred DNS addresses - for example, Google’s DNS:
    • 8.8.8.8
    • 8.8.4.4
  6. Click Apply to save your settings.

✅ Your system will now use the new DNS servers.

💡 Tip: To set IPv6 DNS, switch to the IPv6 tab and use Google’s servers:
2001:4860:4860::8888 and 2001:4860:4860::8844.



💻 Change DNS Nameservers Using the Terminal​

If you prefer command-line control, you can change DNS via Netplan configuration files.

Step 1: Open the Netplan Directory​

Code:
cd /etc/netplan
List the files:
Code:
ls

Then open your network config file (e.g.):
Code:
sudo nano 01-network-manager.yaml



Step 2: Edit the File​

Look for the section that starts with:
Code:
ethernets:
  enp3s0:
    dhcp4: true
    nameservers:
      addresses: [8.8.8.8, 8.8.4.4]
You can replace these IPs with any DNS servers you prefer.
If your file doesn’t have the ethernets or wifis section, add them manually - just keep the correct indentation.

Save the file and exit (CTRL + O, then CTRL + X).



Step 3: Apply the Changes​

Run:
Code:
sudo netplan apply

To confirm the new DNS settings:
Code:
systemd-resolve --status | grep 'DNS Servers' -A2

If everything looks good - you’re done! 🎉



⚡ Why Change DNS Nameservers on Ubuntu?​

There are several benefits to switching DNS servers:
  • 🕒 Faster response times - some third-party DNS providers are quicker than your ISP’s.
  • 🧱 Better uptime - big providers like Google or Cloudflare rarely go down.
  • 🛡️ Improved security - some DNS servers block phishing or malicious sites.
  • 🌍 Access blocked content - changing DNS can help bypass regional restrictions.

⚠️ Note: A fast DNS located far away can sometimes be slower than a closer one due to latency.



🏁 Conclusion​

Changing DNS nameservers on Ubuntu is easy - whether you use the GUI or terminal.
By choosing a faster and safer DNS provider, you can boost performance, enhance security, and enjoy smoother browsing every day. 🌐✨
 
Last edited: