5

I'm trying to add a search line to /etc/resolv.conf

I've added it directly, as an append command in /etc/dhcp/dhclient.conf and as a nameservers block in /etc/netplan/50-cloud-init.yaml.

After roughly an hour, the dhcp and netplan files are intact, but resolv.conf has reverted to not having my search.

I haven't changed /etc/network/interfaces because it says "ifupdown has been replaced by netplan(5) on this system."

Any thoughts on what might be overwriting /etc/resolv.conf besides those two things?

This is ubuntu 18.04 on EC2.

  • 4
    does yours not have a "This file is managed by man:systemd-resolved(8). Do not edit." at the top? :-P – Rinzwind Jun 28 at 19:55
5

There is a complex fight to get control over the resolv.conf file, it is an old fight.

Contenders that try to write a resolv.conf are resolvconf, dhcp, interfaces, network manager and recently systemd-resolved. Other programs also may use resolv.conf, like dnsmasq.

Thus, a simple solution doesn't work in all cases.

  • If you have the resolvconf program installed (which main goal is to take ownership of the resolv.conf file) then: un-install it.

  • If your system use DHCP to get a working IP (most probably you do), every hour or so (depending on system configuration) the IP gets renewed, that re-writes resolv.conf. Detect if this is the source of the problem.

  • The file /etc/interfaces may be used to change the resolv.conf configuration. Find out if it is (and erase it).

  • Network Manager could be configured to change what resolv.conf does. Detect (and erase) if it is doing so.

  • Systemd- resoved may be configured to take control of resolv.conf via a sym-link. Remove the link if it exists.

  • Some recomend to make resolv.conf not modifiable (I believe that is more a problem than a solution). Remove it if it exists.

After you have removed all the above: decide who should keep control of resolv.conf file understanding that DHCP must update the file when a new DHCP lease is obtained.

Ask for more help if needed.

Related:

  1. How to stop dhclient from updating resolvconf on Debian?
  2. How do I stop Debian from overwriting /etc/resolv.conf and overwriting my VPN's nameservers?
  3. resolv.conf overwritten every time
  4. What overwrites /etc/resolv.conf on every boot?
  5. What causing resolv.conf overwritten ?
  6. CentOS 7 NetworkManager Keeps Overwriting /etc/resolv.conf
  7. How do I include lines in resolv.conf that won't get lost on reboot?
4

/etc/resolv.conf is a dynamic configuration file generated by the resolvconf process:

$ head /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
nameserver 127.0.1.1

This file is generated from the files located under /etc/resolvconf/resolv.conf.d/. To write your own changes to the contents of the /etc/resolv.conf simply add the lines that you would usually add to the resolv.conf file instead to the /etc/resolvconf/resolv.conf.d/base file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.