How to avoid that my /etc/resolv.conf get overwriting

January 3, 2018 3.8k views
Linux Basics Ubuntu 16.04

Always I change my DNS in /etc/resolv.conf it change to :


What can I do ?

4 Answers

There should be a warning telling you not to edit resolv.conf. Edit /etc/network/interfaces instead.

  • That looks like it should work since it contains the DNS addresses for Digital Ocean. However changing that file doesn't change the DNS in resolv.conf. At least on Centos.

Or edit /etc/resolvconf/resolveconf.d/base instead. This is used to build resolv.conf

Edit the resolv.conf as you wish, save/close the file and then type this on command line:

chattr +i /etc/resolv.conf ((to protect the file from write))
chattr -i /etc/resolv.conf ((to unprotect, default mode))

editing base file only appends the dns server after the 'head' which is also overwritten but digital ocean. chattr doesn't seem to work either. Anyone have other suggestions?

Have another answer? Share your knowledge.