Detail the solution for CentOS to reset resolv. conf after the CentOS restart

  • 2020-10-23 21:18:06
  • OfStack

Recently, when Modifying dns of one CentOS server, I found that as long as the server is restarted, DNS will be forced to restore. The solution is as follows:

1. First, modify the value of NM_CONTROLLED in the network card setting:

Modify the contents of file /etc/sysconfig/ ES12en-ES13en/ES14en-eth0:


NM_CONTROLLED="no" // Whether to allow Network Manager Manage, set to no

By default, Network Manager is allowed to manage DNS, so first set to no, then operate on DNS Settings

2. Setting DNS content:

Modification of DNS can be done in the following two ways:

Modify the network card Settings:

Modification in /etc/sysconfig/ network-ES37en/ES38en-eth0:


PEERDNS="yes"
DNS1="xxx.xxx.xxx.xxx"
DNS2="xxx.xxx.xxx.xxx"

This setting scheme is based on DNS set in the network card. DNS set in ES44en.ES45en is automatically generated according to the network card setting. If you want to modify DNS in the future, you must modify the setting in the network card to avoid the failure of DNS setting after server restart.

. Directly modify the value of /etc/ ES52en.conf:

It is important to note that the value of PEERDNS in the network card needs to be set as no to ensure that the directly modified DNS content will not be lost after the server is restarted:


nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx

3. Restart the network card after modification:


service network restart

After modifying DNS Settings according to any of the above schemes, the server DNS Settings will not be reset.


Related articles: