I use Ubuntu 20.04 and unfortunately non of the other answers worked for me.
So, I will share the way I fixed the problem below:
First install resolvconf, if it is not already installed
sudo apt update
sudo apt install resolvconf
check that resolvconf service is started and enabled
sudo systemctl status resolvconf.service
If service is not enabled, you can start and enable using the following commands:
sudo systemctl start resolvconf.service
sudo systemctl enable resolvconf.service
Now edit the resolv.conf.d/head configuration file
sudo nano /etc/resolvconf/resolv.conf.d/head
and add your DNS addresses into it (for example I use 8.8.8.8 and 8.8.4.4)
nameserver 8.8.8.8
nameserver 8.8.4.4
Now force resolvconf to run update scripts when invoked with -u
sudo resolvconf --enable-updates
Now run updates
sudo resolvconf -u
Now if you check the content of resolv.conf
file using the following command
cat /etc/resolv.conf
you must see your DNS configuration. If not, try the following commands and check again
sudo systemctl restart resolvconf.service
sudo systemctl restart systemd-resolved.service
References:
https://www.tecmint.com/set-permanent-dns-nameservers-in-ubuntu-debian/
http://manpages.ubuntu.com/manpages/trusty/man8/resolvconf.8.html