/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.


Sreejit is the founder of Server Management Plus. His motto is "If there's an easier way, Why do it any other way" and following it, he has created a lots of automation scripts for the company using which we are able to resolve issue at an extremely fast rate and save lots of time. He has a very keen interest in new technologies and spend most of his free time online researching about it apart from listening music and watching movies.