Many a times, your ISP’s nameservers will be under-performing (slow!) and if you change the nameserver of your Ubuntu system by editing /etc/resolv.conf file, you will find that these changes are not persistent across reboots. If you Google for solutions for this (apparently simple) problem, you will find that most of them are not applicable to latest versions of Ubuntu or Xubuntu (20.04 and above). Here is the best solution for this issue:
First of all, install the resolvconf package if it is not installed already:
sudo apt install resolvconf
Make sure resolvconf was successfully installed and is running:
sudo systemctl status resolvconf.service
You should see “Active: active (exited)” message in green. If you see “Active: inactive (dead)”, you’ll need to enable and start the service as follows:
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.
Now we get to the meat of this article. Let’s open the head file:
sudo vim /etc/resolvconf/resolv.conf.d/head
Enter your nameservers below the comments (I’m using Google’s DNS servers).
nameserver 8.8.8.8
nameserver 8.8.4.4
We need to update resolv.conf to use the new nameservers. Enter the following code:
sudo resolvconf --enable-updatessudo resolvconf -u
Now open resolv.conf to confirm our nameservers have been written to it.
sudo vim /etc/resolv.conf
You should see the following:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 8.8.8.8
nameserver 4.4.4.4
nameserver 127.0.0.53