Set permanent DNS nameservers on Ubuntu/Debian with resolv.conf

Comments 0

Set permanent DNS nameservers on Ubuntu or Debian with resolv.conf

Setting custom DNS servers on Linux can increase performance, security and even thwart some websites using Geo-blocking via DNS. There are several ways to do this including Network Manager GUI that’s included in many Linux distros like Debian, Ubuntu and derivatives, Netplan which is now included as standard in Ubuntu 20.04; or using resolv.conf (not directly, but via the head file). This guide will use resolv.conf, see my other guide for setting custom DNS servers using Network Manager or Netplan.

FYI: The resolv.conf file is overwritten on each boot so we can’t edit this file directly. Instead, we edit one of the two files used to create the resolv.conf file, those being the head and base files. We’ll be editing the head file so that each boot-up, resolv.conf gets written with our custom DNS servers at the top.


Free DNS providers

Before changing DNS servers, you’ll need to find a third-party DNS provider, there are plenty of good (and free) services available. I recommend Google DNS which is what I use and have never had an issue. I will list here the most popular DNS providers:


  • Primary IPv4:
  • Secondary IPv4:
  • Preferred IPv6: 2001:4860:4860::8888
  • Alternate IPv6: 2001:4860:4860::8844


  • Primary:
  • Secondary:
  • Preferred IPv6: 2620:0:ccc::2
  • Alternate IPv6: 2620:0:ccd::2


  • Primary:
  • Secondary:


  • Primary:
  • Secondary:


  • Primary:
  • Secondary:


  • Primary:
  • Secondary:


  • Primary:
  • Secondary:


Installing resolvconf package

Depending on which version of Ubuntu/Debian you’re using, resolvconf may or may not be installed, so let’s check before we continue. Open up a Terminal window and enter the following:

sudo systemctl status resolvconf.service

If you get the following message “Unit: resolvconf.service could not be found” then skip ahead and install resolvconf.

resolvconf service is not installed

If you get this message “Active: active (exited)“ then resolvconf is already installed. Skip to step 2.

resolvconf service is installed

Let’s install the resolvconf package:

sudo apt update
sudo apt install resolvconf

Let’s make sure resolvconf was successfully installed and is running:

sudo systemctl status resolvconf.service

You should see “Active: active (exited)“ message as show below:

resolvconf service is installed

If you see a message “Active: inactive (dead)” you’ll need to enable and start the service.

resolvconf service is installed but not active

Let’s enable and start the resolvconf service:

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

After the last command, you should see the “Active: active (exited)“ message:

resolvconf service is installed

Set DNS servers in resolv.conf using head file

Now we get to the meat of this article. Let’s open the head file:

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

Enter your nameservers below the comments (I’m using Google’s DNS servers).

resolvconf head file, enter DNS IP addresses

Then save ctrl + o, ENTER and exit nano ctrl + x.

We need to update resolv.conf to use the new nameservers:

sudo resolvconf --enable-updates
sudo resolvconf -u

Now open resolv.conf to confirm our nameservers have been written to it:

sudo nano /etc/resolv.conf

You should see your DNS server IP’s for the nameserver option:

resolvconf with your chosen DNS IP addresses

Video: Set permanent DNS nameservers on Ubuntu/Debian with resolv.conf


I hope this guide helped you to set your custom (and permanent) DNS servers for your Ubuntu or Debian machine. If you had any trouble or just want to say hi, leave a comment and I’ll help you out.

Newsletter Signup

Privacy Policy

See Also

Further Reading

Categories Debian, Ubuntu


There are currently no comments on this article.


Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.

PLEASE NOTE: You must preview a comment before submitting

Comments use Textile formatting