The other day, I was having some problems with Network Manager (I only ever have problems with it to be honest). It kept overwriting my /etc/resolv.conf — the file where you configure what nameservers your system will use.
Even after I uninstalled Network Manger, on rebooot I would find my resolv.conf saying it had been
generated by Network Manager.
I turned to a trick that I very rarely use, but which is useful from time to time. I set the immutable attribute on the file. The immutable attribute means that no user, not even root, can modify the file without also unsetting the attribute.
You can view the current attributes of a file any time using lsattr
You use the chattr command to set the attribute. You might need root, deending on the file.
chattr +i resolv.conf
So that now lsattr shows
$ lsattr /etc/resolv.conf
Now you cannot change the file at all!
$ sudo rm /etc/resolv.conf
rm: cannot remove â€˜/etc/resolv.confâ€™: Operation not permitted
You can unset the immutable attribute using -i
chattr -i resolv.conf
There are a bunch more attributes listed in the chattr man page though this is the only one I ever seem to find myself using.
GNU/Linux image from soft-ulibre.gaeon.com