Solution for resetting resolv. conf after CentOS is restarted

Source: Internet
Author: User
Tags centos server nameserver

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.