I use ubuntu 20.04 and unfortunately non of the other answers worked for me
so I share the way I fixed this problem
first install resolvconf if not installed
sudo apt update
sudo apt install resolvconf
check resolvconf service started and enabled
sudo systemctl status resolvconf.service
if service is not enabled you can start and enable it with :
sudo systemctl start resolvconf.service
sudo systemctl enable resolvconf.service
now edit resolv.conf.d/head configuration file
sudo nano /etc/resolvconf/resolv.conf.d/head
add your DNS addresses to this file 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 cat /etc/resolv.conf
you must see your DNS configuration in this file if not try these commands and check again
sudo systemctl restart resolvconf.service
sudo systemctl restart systemd-resolved.service
Resources:
https://www.tecmint.com/set-permanent-dns-nameservers-in-ubuntu-debian/
http://manpages.ubuntu.com/manpages/trusty/man8/resolvconf.8.html