2

I have a problem where the line nameserver 8.8.8.8 just disappears from my /etc/resolv.conf.

This might happen every few days or so and I haven't noticed anything that would be linked to this issue. Then I add it back manually and restart my forever looping scripts. This is pretty annoying to do and I'd like to know why this happens.

Ledi
  • 21

3 Answers3

2

To add permanent lines in /etc/resolv.conf you could install the resolvconf command line:

sudo apt install resolvconf

then you have to edit /etc/resolvconf/resolv.conf.d/head and add the permanent lines you need. For example:

nameserver 8.8.8.8
nameserver 1.1.1.1

and finally run these commands:

sudo resolvconf --enable-updates
sudo resolvconf -u

Maybe you need to restart the network interface after that, but I'm not sure.

0

At reboot /etc/resolve.conf usually regenerated and can be rewritten / created on occasion by your DHCP or other services. You can try to disable getting dns-nameservers from your DHCP server if it's the case.

dhclient usually overcomes most resolvconf files. So updating your /etc/dhcp/dhclient.conf and /etc/network/interfaces files can work.

Answers and opinions for a similar issue can be found here

  • I forgot to mention but this happens without rebooting. Uptime on this machine is 35days and I remember this happening a few times during this uptime. – Ledi Dec 21 '21 at 21:00
  • Well you can change the write permission of resolve.conf to make sure it's not writable. Not the best solution probably but worked in my case sometime ago. You can simply use chattr +i /etc/resolv.conf to make it write protected, chattr -i /etc/resolv.conf to make it writable again. About why it happens, I can list numerous reasons. It's probably faster and easier to just overcome it rather than searching for the root cause. – Armageddon_0x00 Dec 21 '21 at 21:14
  • using chattr on resolv.conf is fixing the wrong problem. – user10489 Dec 21 '21 at 21:33
0

Multiple services including netplan, network-manager, and dhcpd all need to make changes to resolv.conf to reflect current network configuration.

Typically in an ubuntu system, the systemd-resolve and resolvconf services try to juggle this, and you will find that the file /etc/resolv.conf is actually a symlink to /var/run/resolvconf/resolv.conf.

If you want to make permanent changes to this file, you need to make the changes in one of the controlling subsystems, such as netplan or network-manager.

If you don't want that file to be automatically managed, you can delete the symlink and recreate it as a regular file. However, this may break things like VPN, DHCP, and dynamic network changes you get when you move from one physical network to another.

user10489
  • 4,051