All ArticlesDNS2026-11-05T11:14:54+08:00

Edited /etc/resolv.conf and It Reverted After Reboot? Find What Manages It

Admins change nameservers in /etc/resolv.conf, then find the file overwritten after a reboot or network restart. The article explains how systemd-resolved, NetworkManager, cloud-init, and DHCP clients each take ownership of the file, and how to set DNS servers in the right place so the change persists.

You open /etc/resolv.conf, replace the nameserver lines with the resolvers you want, and lookups start working the way you expect. Then the server reboots, or the network restarts, or a DHCP lease renews, and the file is back to what it was. Nothing is broken. On most modern Linux systems, /etc/resolv.conf is an output file that some other program writes, and that program just wrote it again.

The fix is never to edit the file harder. It is to find out who owns it and give that owner your DNS servers.

What actually reads /etc/resolv.conf

When a program calls getaddrinfo() to turn a hostname into an address, the C library (glibc on most distros) first checks /etc/nsswitch.conf. The hosts: line there lists the sources to try in order, typically files first (meaning /etc/hosts) and then dns. When it reaches the dns source, glibc reads /etc/resolv.conf, takes the nameserver lines (only the first three are used), applies any options and search domains, and sends a UDP query to the first server on port 53.

That is the whole contract. glibc does not care who wrote the file or how. It just reads whatever is there at lookup time, and current glibc versions notice when the file changes and reload it. This simplicity is exactly why so many components want to manage it. The file is the single place where every program on the box picks up its resolver, so any daemon that learns about DNS servers from the network (a DHCP server, a cloud metadata service, a VPN) wants to write them there.

The result is a last-writer-wins file. Your manual edit is just one more write, and it loses the next time the real owner runs.

Finding the owner in about a minute

The owner usually leaves fingerprints: the file is a symlink into a runtime directory, or it starts with a generated-by comment, or a known service is active. These read-only checks cover most cases.

# Is it a regular file or a symlink, and where does it point?
ls -l /etc/resolv.conf

# Generated files usually say who generated them in the first lines
head -n 5 /etc/resolv.conf

# Which managers are running?
systemctl is-active systemd-resolved NetworkManager systemd-networkd

# Is cloud-init present, and is netplan in use?
cloud-init status 2>/dev/null
ls /etc/netplan/ 2>/dev/null

# If systemd-resolved is active, see which upstream servers it uses per link
resolvectl status

Read the results together. This table maps the common fingerprints to the place where DNS should be configured instead.

FingerprintOwnerWhere to set DNS
Symlink to /run/systemd/resolve/stub-resolv.conf, nameserver 127.0.0.53systemd-resolvedresolved.conf drop-in, or netplan / systemd-networkd for the link
Comment saying Generated by NetworkManagerNetworkManagernmcli connection settings
Symlink to /run/resolvconf/resolv.conf, header mentioning resolvconf(8)resolvconfInterface config that feeds resolvconf
Plain file rewritten on lease renewal, dhclient runningdhclient-scriptdhclient.conf
/etc/netplan/50-cloud-init.yaml exists, cloud-init activecloud-init generating netplancloud-init config, or disable its network rendering

Owners can also stack. On an Ubuntu cloud image, cloud-init writes netplan, netplan generates systemd-networkd config, networkd gets DNS from DHCP and hands it to systemd-resolved, and resolved writes the file. Fixing the bottom layer while the top layer regenerates everything is a common reason a fix holds until the next reboot and then disappears.

systemd-resolved: the stub and the real list

When resolv.conf shows nameserver 127.0.0.53, programs are not talking to any upstream DNS server directly. They send queries to a small listener that systemd-resolved runs on the loopback address. resolved then forwards each query to the upstream servers it knows about, caches the answer, and returns it.

resolved keeps two lists of upstream servers. Global servers come from DNS= in /etc/systemd/resolved.conf. Per-link servers are pushed in by whatever manages each interface, usually systemd-networkd or NetworkManager, and those often come from DHCP. resolved writes /run/systemd/resolve/stub-resolv.conf pointing at itself, and /etc/resolv.conf is a symlink to it. /run is a tmpfs, so it is rebuilt from scratch on every boot. Editing /etc/resolv.conf through that symlink edits a file that is gone after a reboot, and resolved may overwrite it sooner when link state changes.

To set servers persistently, use a drop-in rather than the main file:

# /etc/systemd/resolved.conf.d/dns.conf
[Resolve]
DNS=1.1.1.1 9.9.9.9
# Optional: send all queries to the global servers above,
# not only queries that match no link-specific domain
Domains=~.

Then restart the service with systemctl restart systemd-resolved and confirm with resolvectl status. One detail trips people up here: per-link servers from DHCP still exist alongside your global ones. If the goal is to stop using the provider's DHCP resolvers entirely, turn that off at the link level, for example with dhcp4-overrides and use-dns: false under the interface in netplan, followed by netplan apply. Before doing that on a VPS, check whether anything depends on the provider's resolvers, such as private hostnames or internal services.

If you see a list of real upstream servers in resolv.conf and the symlink points at /run/systemd/resolve/resolv.conf instead, resolved is still the owner. It is just exposing its upstream list instead of the stub, so the same configuration applies.

NetworkManager: connection profiles win

NetworkManager stores DNS settings per connection profile, not in resolv.conf. Every time a connection comes up, it rebuilds the resolver configuration from the active profiles plus whatever DHCP handed it. How it writes that out depends on the dns= setting in NetworkManager.conf or its conf.d drop-ins. It may write /etc/resolv.conf directly, hand servers to systemd-resolved, or leave the file alone if set to none. Defaults vary by distro, so read your config rather than assuming.

The persistent fix is to set DNS on the profile and tell it to ignore DHCP-supplied servers:

# Find the profile name first
nmcli connection show

# Set static DNS and ignore DHCP-provided servers for IPv4
nmcli connection modify 'System eth0' ipv4.dns '1.1.1.1 9.9.9.9' ipv4.ignore-auto-dns yes

# Re-activate the profile to apply (briefly interrupts this interface)
nmcli connection up 'System eth0'

Replace the profile name with your own. If you are connected over SSH on that same interface, the reactivation usually comes back fine, but a typo in other settings can drop the connection, so have console access ready on a remote server. Do the same for ipv6.dns if the box resolves over IPv6.

DHCP clients and cloud-init: the quiet rewrites

On systems without NetworkManager or resolved managing DNS, the classic owner is the DHCP client. dhclient runs a hook script on lease events such as bound and renew, and that script rewrites resolv.conf with the servers from the lease. This is why some servers revert in the middle of the day with no reboot at all: the lease renewed. The fix lives in the client config, usually /etc/dhcp/dhclient.conf, with a line like supersede domain-name-servers 1.1.1.1, 9.9.9.9; so the client replaces whatever the DHCP server offers. If resolvconf is installed, the hook passes servers to it instead, and resolvconf assembles the final file from interface data, so configure the interface rather than the output.

cloud-init sits one level higher. On a cloud VPS it reads network configuration from the provider's metadata and renders it into the OS's native format, for example netplan on Ubuntu. Depending on the distro, datasource, and version, it may render that config again on later boots, which overwrites hand edits to the generated files. You have two clean options. Supply DNS through the provider's network or cloud-init config, so the source itself is correct. Or tell cloud-init to stop managing networking by creating a file such as /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled}, then maintain your own netplan file. The second option means you now own networking on that box, including whatever the provider changes later.

Containers add another layer. In an LXC container on Proxmox, the host can inject resolver settings at container start, which is covered in Why Proxmox Keeps Overwriting resolv.conf in Your LXC Container After Migration.

About chattr +i

A common workaround is to replace the symlink with a regular file and mark it immutable with chattr +i. It does stop the overwrite. It also leaves the managers running and failing silently against a file they cannot write, ignores legitimate changes from DHCP or a VPN, and confuses whoever touches the server next, because the file looks normal and nothing explains why it cannot be edited. It is a reasonable short-term patch during an incident. As a permanent setup it usually creates the next ticket.

From the support side, the first question to ask is not which nameservers someone wants but whether /etc/resolv.conf is a symlink. That one ls -l answers most of the case.

The practical rule: treat /etc/resolv.conf as a report, not a setting. Check the symlink, the header comment, and which services are active, follow the chain up to the top-most component that generates configuration, and set DNS there. Then reboot once on purpose and confirm with resolvectl status or a plain look at the file, so the next surprise reboot is not the one that tells you whether it held.