The /etc/resolv.conf is the main configuration file for the DNS name resolver library. The resolver is a set of functions in the C library that provide access to the Internet Domain Name System (DNS). The functions are configured to check entries in the /etc/hosts file, or several DNS name servers, or to use the host’s database of Network Information Service (NIS).
On modern Linux systems that use systemd (system and service manager), the DNS or name resolution services are provided to local applications via the systemd-resolved service. By default, this service has four different modes for handling the Domain name resolution and uses the systemd DNS stub file (/run/systemd/resolve/stub-resolv.conf) in the default mode of operation.
The DNS stub file contains the local stub 127.0.0.53 as the only DNS server, and it is redirected to the /etc/resolv.conf file which was used to add the name servers used by the system.
If you run the following ls command on the /etc/resolv.conf, you will see that this file is a symlink to the /run/systemd/resolve/stub-resolv.conf file.
$ ls -l /etc/resolv.conf lrwxrwxrwx 1 root root 39 Feb 15 2019 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
Unfortunately, because the /etc/resolv.conf is indirectly managed by the systemd-resolved service, and in some cases by the network service (by using initscripts or NetworkManager), any changes made manually by a user can not be saved permanently or only last for a while.
In this article, we will show how to install and use the resolvconf program to set permanent DNS name servers in /etc/resolv.conf file under Debian and Ubuntu Linux distributions.
Why Would You Want to Edit /etc/resolv.conf File?
The main reason could be because the system’s DNS settings are misconfigured or you prefer to use specific name servers or your own. The following cat command shows the default name server in the /etc/resolv.conf file on my Ubuntu system.
$ cat /etc/resolv.conf

In this case, when local applications such as the APT package manager try to access FQDNs (Fully Qualified Domain Names) on the local network, the result is a “Temporary failure in name resolution” error as shown in the next screenshot.

The same happens when you run a ping command.
$ ping google.com

So when a user tries to manually set the name servers, the changes do not last for long or are revoked after a reboot. To resolve this, you can install and use the reolvconf utility to make the changes permanent.
To install the resolvconf package as shown in the next section, you need to first manually set the following name servers in the /etc/resolv.conf file, so that you access the FQDMs of Ubuntu repository servers on the internet.
nameserver 8.8.4.4 nameserver 8.8.8.8
Read Also: How to Setup Local DNS Using /etc/hosts File in Linux
Installing resolvconf in Ubuntu and Debian
First, update the system software packages and then install resolvconf from the official repositories by running the following commands.
$ sudo apt update $ sudo apt install resolvconf
Once the resolvconf installation is complete, the systemd will trigger the resolvconf.service to be automatically started and enabled. To check if it is up and running issues the following command.
$ sudo systemctl status resolvconf.service
If the service is not started and enabled automatically for any reason, you can start and enable it as follows.
$ sudo systemctl start resolvconf.service $ sudo systemctl enable resolvconf.service $ sudo systemctl status resolvconf.service

Set Permanent DNS Nameservers in Ubuntu and Debian
Next, open the /etc/resolvconf/resolv.conf.d/head configuration file.
$ sudo nano /etc/resolvconf/resolv.conf.d/head
and add the following lines in it:
nameserver 8.8.8.8 nameserver 8.8.4.4

Save the changes and restart the resolvconf.service and systemd-resolved or reboot the system.
$ sudo systemctl restart resolvconf.service $ sudo systemctl restart systemd-resolved.service
Now when you check the /etc/resolv.conf file, the name server entries should be stored there permanently. Henceforth, you will not face any issues concerning name resolution on your system.

I hope this quick article helped you in setting the permanent DNS nameservers in your Ubuntu and Debian systems. If you have any queries or suggestions, do share them with us in the comments section below.
I worked however I needed to reboot the server so just restarting the service might not be enough.
Thank you, it worked correctly.
Hi, there I was wondering whether these changes remain permanent no matter if /etc/interfaces are modified or not. Doesn’t Network Manager erase any modifications to resolv.conf on reboot?
Hi,
Thank you for this article. I tried to apply it but my problem is how I get resolvconf without DNS working. When manually I add 8.8.8.8 to the /etc/resolv.conf it doesn’t take effect I need to restart the network or reboot when I do so the file gets empty again.
If there is any solution to that thank you for sharing it.
Did you resolve the issue, if yes please post
Did you run
`sudo resolvconf -u`
at the end?I think I messed something up. I added my nameservers, restarted the computer, but couldn’t access websites.
I am trying to use 1.1.1.1 as DNS
Maybe I am missing something. When you try to manually create it, you get the error messages below.
I don’t know why you didn’t mention how to do the manual change.
@Nick,
Use sudo while opening the file.
$ sudo vi /etc/resolv.conf
you need to edit with sudo
Works fine, I just had to run `sudo resolvconf -u` at the end
Thank you
I forgot to tell, my config: Debian 10 Buster.
More precisely Linux 4.19.0-11-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64 GNU/Linux
Thanks, @iaeiou — that did the trick to me as well. I was scratching my head to figure out what else I had to do to get the system to accept my configuration, and I knew it had to work somehow since I had changed everything to Google back in 2016… so there was no reason for things not to work in 2020 with Cloudflare’s servers (1.1.1.1 and 1.0.0.1)!
I guess that Aaron Kili has to update his original article to take the resolvconf -u into account.
Ubuntu girl here, using Ubuntu 20.04.1 LTS (focal) on a 5.4.0-52-generic kernel. So this seems to be consistent between Debian and Ubuntu (as it should!).
I downloaded resolvconf_1.82_all.deb and copied it to the broken system. Then installed with dpkg -i resolvconf_1.82_all.deb.
Nothing I do fixes my DNS issues.
I can’t understand where that 10.0.0.1 is coming from??
You haven’t put the google DNS address in the config.
Did I miss something? How I can install resolvconf if I had no access to the network?
Check the part starting with “To install the resolvconf package as shown in the next section, you need to first of all manually set the following name servers in the /etc/resolv.conf file”
Was looking to use OpenDNS nameservers to prevent a multitude of Postfix dnsblog_query errors with Spamhaus, but couldn’t figure out how to make them stick. This article was from heaven.
Many, many, many thanks.