Solution for resetting resolv. conf after CentOS is restarted
Recently, when modifying the dns of a CentOS server, it is found that the server DNS will be forcibly restored as long as it is restarted. The solution is as follows:
1. First, modify the value of NM_CONTROLLED In the NIC settings:
Modify the file/etc/sysconfig/network-scripts/ifcfg-eth0 content:
NM_CONTROLLED = "no" // whether to allow Network Manager Management and set it to no
By default, Network Manager is allowed to manage DNS, so first set it to no and then perform DNS settings
2. Set DNS content:
You can modify DNS in two ways:
① Modify Nic settings:
In/etc/sysconfig/network-scripts/ifcfg-eth0, modify the following content:
PEERDNS = "yes"
DNS1 = "xxx. xxx"
DNS2 = "xxx. xxx"
This setting scheme is based on the DNS set in the NIC, resolv. the conf file is automatically generated according to the DNS content set by the NIC. to modify the DNS later, you must modify the settings in the NIC so that the DNS settings do not expire after the server is restarted.
② Directly modify the value of/etc/resolv. conf:
PS. It should be noted that to prevent direct modification of DNS content from being lost after server restart, you need to set the PEERDNS value in the NIC to no:
Nameserver xxx. xxx
Nameserver xxx. xxx
3. Restart the NIC after modification:
Service network restart
After you modify the DNS settings according to any of the above schemes, the server will not be restarted and the DNS settings will be restored.
Https://www.bkjia.com/topicnews.aspx? Tid = 14
This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151549.htm