Ubuntu DNS resolver issue is observed on ubuntu 18.04 onwards that /etc/resolv.conf keeps changing or over written even if the server is not rebooted nor the network service has been restarted.
Install resolvconf to resolve ubuntu dns resolver issue
sudo apt-get install resolvconf
Now lets go to below file and add our dns server
vi /etc/resolvconf/resolv.conf.d/head
# 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 192.168.2.2
Once our required dns servers are added to the head file, we need to restart the resolvconf service.
sudo systemctl restart resolvconf
sudo systemctl status resolvconf
● resolvconf.service - Nameserver information manager
Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor prese
Active: active (exited) since Tue 2021-12-14 08:34:38 IST; 16s ago
Docs: man:resolvconf(8)
Process: 14624 ExecStop=/sbin/resolvconf --disable-updates (code=exited, statu
Process: 14645 ExecStart=/sbin/resolvconf --enable-updates (code=exited, statu
Process: 14642 ExecStartPre=/bin/touch /run/resolvconf/postponed-update (code=
Process: 14634 ExecStartPre=/bin/mkdir -p /run/resolvconf/interface (code=exit
Main PID: 14645 (code=exited, status=0/SUCCESS)
Dec 14 08:34:38 makeuseoflinux.com systemd[1]: Starting Nameserver information m
Dec 14 08:34:38 makeuseoflinux.com systemd[1]: Started Nameserver information
We can now see the new dns entry inside /etc/resolv.conf
cat /etc/resolv.conf
# 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 192.168.2.2
We can also check the dns status using below command
systemd-resolve --status
systemd-resolve --status
Global
DNS Servers: 192.168.2.2
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
22.172.in-addr.arpa
23.172.in-addr.arpa
Solution
We have resolved ubuntu dns resolver issue by installing resolvconf package using apt-get and then added our required dns server in /etc/resolvconf/resolv.conf.d/head