Solution to invalid centos DNS resolv restart

Source: Internet
Author: User
Tags nameserver

You cannot directly modify/etc/resolv. conf. You must add the DNS settings in/etc/sysconfig/network-scripts/ifcfg-eth0. Otherwise, after the restart, you must use the eth0 settings without DNS information to restore/etc/resolv. conf to the original state.

Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Device = eth0
Bootproto = none
Hwaddr = 00: XX: 19: XX: xx
Onboot = Yes
Type = Ethernet
Userctl = No
Ipv6init = No
Peerdns = Yes
Netmask = 255.255.255.0
Ipaddr = XXX. XXX
Gateway = XXX. XXX
Dns1 = 202.96.209.5 # Shanghai DNS, changed according to the actual situation
Dns2 = 202.96.209.20.# Shanghai DNS, changed according to the actual situation

In this case, you do not need to set it in/etc/resolv. conf.
After Service Network restart, we can find that there are two DNS resolution IP addresses in/etc/resolv. conf.

CAT/etc/resolv. conf

Generated by NetworkManager
Nameserver 202.96.209.5
Nameserver 202.96.209.20.
Search localdomain

DNS resolution settings are successful.
It should be emphasized that/etc/resolv is directly modified. conf file is useless, the network service will restart according to/etc/sysconfig/network-scripts/ifcfg-eth0 to reload the configuration, if the ifcfg-eth0 does not configure DNS, then resolv. conf will be washed out and then become a null value.

Well, I don't know why this has not happened to the previously installed system?

Modify the host file
Open the host file

/Etc/hosts

Add the required items in the following format:

Format:

<Ip>

Example:

216.239.37.99 www.2cto.com

After editing, You need to restart your network.

/Etc/init. d/networking restart

Original article: http://www.2cto.com/ OS /201208/147086.html

Related Article

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.