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, 2019 at 19:55

2 Answers 2


There is a complex competition to get control of the resolv.conf file, it is a very old competition.

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 (whose main goal is to take ownership of the resolv.conf file) then: un-install it.

  • If your system uses 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-resolved may be configured to take control of resolv.conf via a sym-link. Remove the link if it exists.

  • Some recommend 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 the resolv.conf file understanding that DHCP could update the file when a new DHCP lease is obtained. If the ISP (or upstream dhcp server owner) dns server is the one that should be used. DHCP leases could be configured to change the IP but not update the resolv.conf file, or an alternate dnsmasq/resolv.conf could be used if a local ( DNS server (well, mostly like a catching server) is setup with dnsmasq. Of course, more complex configurations could be built with bind9, Unbound, NSD and many others.

Ask for more help if needed.


  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?
  8. Arch linux OpenResolv.
  • I'm undeleting this as it provides lots of places to look for "what might be overwriting /etc/resolv.conf?"
    – Jeff Schaller
    May 20 at 13:04

/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)

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.