/etc/resolv.conf Keeps Resetting After Reboot — and How to Own It

resolv.conf isn't really a file you own — systemd-resolved, NetworkManager, or cloud-init regenerate it. Edit the manager, not the file, or your change evaporates at the next boot.

What you'll see

Root causes

systemd-resolved owns the file

resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf. Change DNS via netplan/NetworkManager so the config survives, or re-point the symlink at a static file.

DHCP/cloud-init rewrites it

Cloud images regenerate netplan/NetworkManager config on boot: your hand-edit lasts until the next DHCP lease. The durable fix is cloud-init user data / netplan files, not the file itself.

Fix it

  1. See who owns the file in your case
    ls -l /etc/resolv.conf ; head -3 /etc/resolv.conf   # symlink target / header comment names the manager
  2. Set DNS at the right layer (netplan example)
    # /etc/netplan/01-dns.yaml: nameservers: { addresses: [1.1.1.1, 8.8.8.8] } ; then: sudo netplan apply
  3. Or make the file yours permanently (last resort)
    sudo rm /etc/resolv.conf && printf 'nameserver 1.1.1.1\nnameserver 8.8.8.8\n' | sudo tee /etc/resolv.conf
  4. For systemd-resolved: set DNS and confirm
    resolvectl status | head -20   # shows the per-link DNS actually in use

Field note

resolv.conf immutable-flag hacks (chattr +i) work but fight the distro — prefer the manager's own config. DNS_PROBE/NXDOMAIN issues that appear 'randomly' after edits are usually this exact regeneration racing you.

Common questions

Why is my resolv.conf a symlink?

systemd-resolved setups point it at a runtime stub (127.0.0.53) that forwards to the real per-link resolvers. Editing the symlink target does nothing durable — configure resolved/netplan instead.

What's the cleanest permanent fix on servers?

Declare DNS in the netplan/NetworkManager/cloud-init layer (whichever your distro uses) and never touch resolv.conf by hand. The file becomes an output, not an input.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.