/etc/resolv.conf overwritten in CentOS 7

In CentOS 7 you will often find /etc/resolv.conf overwritten after each reboot or network service restart. It’s done the NetworkManager. If you check your resolv.conf after reboot you will see that your changes are gone and it will look something like this

[root@cpanel ~]# cat /etc/resolv.conf
search domain.tld
# Generated by NetworkManager
[root@cpanel ~]#

This happens because of the DNS entries present in the network interface files. Check for DNS1 and DNS2 entries in the network config files and and remove them.

[root@cpanel ~]# cd /etc/sysconfig/network-scripts
[root@cpanel network-scripts]# grep DNS ifcfg-*
[root@cpanel network-scripts]#

I above example removing the “DNS1=” entry from the ifcfg-ens160 file will solve the problem.