Multiple services including netplan, network-manager, and dhcpd all need to make changes to resolv.conf to reflect current network configuration.
Typically in an ubuntu system, the systemd-resolve and resolvconf services try to juggle this, and you will find that the file /etc/resolv.conf is actually a symlink to /var/run/resolvconf/resolv.conf.
If you want to make permanent changes to this file, you need to make the changes in one of the controlling subsystems, such as netplan or network-manager.
If you don't want that file to be automatically managed, you can delete the symlink and recreate it as a regular file. However, this may break things like VPN, DHCP, and dynamic network changes you get when you move from one physical network to another.
resolve.confto make sure it's not writable. Not the best solution probably but worked in my case sometime ago. You can simply usechattr +i /etc/resolv.confto make it write protected,chattr -i /etc/resolv.confto make it writable again. About why it happens, I can list numerous reasons. It's probably faster and easier to just overcome it rather than searching for the root cause. – Armageddon_0x00 Dec 21 '21 at 21:14