/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
nameserver 208.67.222.222
[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-*
ifcfg-ens160:PEERDNS=yes
ifcfg-ens160:IPV6_PEERDNS=yes
ifcfg-ens160:DNS1=208.67.222.222
[root@cpanel network-scripts]#

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