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

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
  • 5,533