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.
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.
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.
ls -l /etc/resolv.conf ; head -3 /etc/resolv.conf # symlink target / header comment names the manager
# /etc/netplan/01-dns.yaml: nameservers: { addresses: [1.1.1.1, 8.8.8.8] } ; then: sudo netplan apply
sudo rm /etc/resolv.conf && printf 'nameserver 1.1.1.1\nnameserver 8.8.8.8\n' | sudo tee /etc/resolv.conf
resolvectl status | head -20 # shows the per-link DNS actually in use
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.
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.
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.
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.