Home Ubuntu How to set permanent DNS Nameservers in Ubuntu

How to set permanent DNS Nameservers in Ubuntu

Setting permanent DNS nameservers in Ubuntu is essential for a stable network connection. This guide explains how to configure DNS settings using Netplan or resolv.conf, depending on your Ubuntu version, to ensure your system consistently uses your preferred DNS servers for all network activities.

by Arun Kumar
setting up permanent dns nameservers

Today, we delve into the simple yet impactful process of setting permanent DNS nameservers in Ubuntu. Whether you’re running the latest version or sticking with an older one, this guide will walk you through each step, ensuring your browsing experience is fast, secure, and tailored to your preferences. From choosing the right DNS server to FAQs, we’ve got you covered.

Understanding DNS and its importance

Before we jump into the technical stuff, let’s understand why DNS matters. Imagine DNS as the internet’s phonebook. Without it, you would need to remember the IP addresses of all your favorite websites. Not fun, right? By setting a permanent DNS, you can often get faster browsing speeds and enhanced privacy. Personally, I’ve noticed a significant improvement in my browsing experience after switching to a more reliable DNS server.

Choosing the right DNS server

There are many DNS servers out there, like Google DNS ( and and Cloudflare DNS ( and I prefer Cloudflare for its privacy policy and speed, but the choice is yours. Make sure to research and choose one that best fits your needs.

Setting permanent DNS nameservers in Ubuntu

Now, let’s get to the main event. Setting a permanent DNS in Ubuntu is a straightforward process, but it’s crucial to follow the steps carefully based on the Ubuntu version you have.

Method 1: Using resolvconf (For Ubuntu 18.04 and earlier):

Older versions of Ubuntu use resolvconf to manage DNS settings. Here’s how you can set permanent DNS nameservers using this method.

Step 1: Install resolvconf

First, ensure resolvconf is installed. Open your terminal (Ctrl + Alt + T) and enter:

sudo apt-get update
sudo apt-get install resolvconf

Step 2: Enable the service

Make sure the service is enabled:

sudo systemctl enable resolvconf.service
sudo systemctl start resolvconf.service

Step 3: Edit the resolvconf head file

Now, edit the head file of resolvconf:

sudo nano /etc/resolvconf/resolv.conf.d/head

Step 4: Add your DNS nameservers

At the end of the file, add your desired DNS nameservers. Here’s an example showing the addition of Google’s DNS:


Replace these with your chosen DNS servers.

Step 5: Update resolvconf

After saving and closing the file (Ctrl + O, Enter, then Ctrl + X), update resolvconf:

sudo resolvconf -u

Step 6: Restart the resolvconf service (optional, but I recommend it):

sudo systemctl restart resolvconf.service

Step 7: Verify the changes

Check if your new settings are active:

cat /etc/resolv.conf

You should see your DNS servers listed.

Method 2: Using Netplan (for Ubuntu 20.04 and later):

Step 1: Open the terminal

First things first, open your terminal. You can do this by pressing Ctrl + Alt + T. Ah, the familiar black screen with a blinking cursor – it feels like home, doesn’t it?

Step 2: Edit the Netplan configuration file

Ubuntu uses Netplan for network configuration. You’ll need to edit the Netplan YAML file. Type the following command:

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

Replace 01-netcfg.yaml with your YAML file name, as it might differ.

Step 3: Modify the file

Here, you’ll see the network configuration. We’ll add our DNS servers. Under the ethernets or wifis section, depending on your connection, add the following lines:

addresses: [,]

Replace and with your chosen DNS servers. Ensure the indentation is correct – YAML is picky about that.

Step 4: Apply changes

Save the file (Ctrl + O, then Enter) and exit (Ctrl + X). Apply the changes with:

sudo netplan apply

Step 5: Verify the changes

To ensure your settings are applied, check with:

systemd-resolve --status

Look for the DNS Servers section in the output. You should see the DNS servers you set.

Frequently Asked Questions (FAQs)

1. What is DNS and why is it important?

DNS, or Domain Name System, translates human-readable domain names (like www.example.com) into IP addresses that computers use. It’s crucial for helping us browse the internet easily, without memorizing complex numbers.

2. How do I choose a DNS server?

Select a DNS server based on reliability, speed, and privacy policies. Popular choices include Google DNS ( and and Cloudflare DNS ( and Do some research to find what suits your needs best.

3. Can I use different DNS servers for different network connections?

Yes, in Ubuntu, you can configure different DNS servers for different networks by modifying the Netplan or resolvconf configurations for each connection.

4. Will changing my DNS server impact my internet speed?

It can. A faster DNS server can speed up the time it takes to resolve domain names, which might make your overall browsing experience quicker.

5. Is it safe to use third-party DNS servers?

Generally, yes, but it’s important to choose reputable DNS providers. Consider their privacy policies and history of reliability.

6. What should I do if my internet stops working after changing DNS settings?

Recheck your configuration for any errors. If unsure, revert to your original settings or use a well-known DNS server like Google DNS.

7. How often should I update my DNS settings?

There’s no need for regular updates unless you’re experiencing issues or your DNS provider changes their settings.

8. Can changing DNS settings improve my privacy?

Yes, some DNS providers offer enhanced privacy features, like not logging your queries. Read the provider’s privacy policy for details.

9. Are there any risks to changing DNS settings?

The risk is minimal if you use reputable DNS servers. The main issue is entering the wrong settings, which could temporarily disrupt your internet connection.


Setting permanent DNS nameservers in Ubuntu is more than a technical task; it’s a step towards a smoother, more private internet experience. We explored two methods catering to different Ubuntu versions, ensuring that everyone, regardless of their system, can benefit.

This guide aimed to demystify the process, making it accessible and easy to follow. By choosing the right DNS server and following the steps outlined, you can significantly enhance your browsing experience, proving once again the flexibility and power of Ubuntu.

You may also like

Leave a Comment



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us


©2016-2023 FOSS LINUX



“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.