If you have encountered issues with Ubuntu DNS resolution in a home lab or production environment, chances are, it may be the systemd-resolved service that is causing issues. By default Ubuntu installs the systemd-resolved service which points the Ubuntu server to a symlinked file located at /etc/resolv.conf.
I will show you the workaround steps to disable the systemd-resolved service and remove the symlink file and enter your own DNS settings in a non-symlinked file at this location.
Stop the service
Below, stop the service and disable it. Then you can mask the service.
sudo systemctl stop systemd-resolved sudo systemctl disable systemd-resolved sudo systemctl mask systemd-resolved
Check for symlink
Below is optional, but you can check to see if the file is indeed a symlink.
ls -l /etc/resolv.conf
Remove symlink
Remove the symlink.
sudo rm /etc/resolv.conf
Create a new file
Below is an example of how you can easily configure the file with your own values. Below I am pointing to my DNS server at 10.1.149.10 and the internal DNS search domain "cloud.local" and entering this into the /etc/resolv.conf file.
bash -c 'echo -e "nameserver 10.1.149.10\nsearch cloud.local" > /etc/resolv.conf'
Set the file to immutable
sudo chattr +i /etc/resolv.conf
The above will make sure this file can't be changed by other processes or anything that tries to modify this file.
Using these steps you will find that your DNS resolution will likely work much better and have more consistent behavior that you would expect if you have a DNS server that you want to point your Ubuntu server to.