Workaround for /etc/resolv.conf changes lost after reboot

Transferred from http://hi.baidu.com/iamcyh/blog/item/4cfa1c021e9630f208fa9300.htmlSolution

:

Add the PEERDNS option to the /etc/sysconfig/network-scripts/ifcfg-eth<N> file. <N> can be 0, 1, 2, etc., representing the configuration files of different network cards. For example, if the first network card on the system is eth0, its configuration file is /etc/sysconfig/network-scripts/ifcfg-eth0.

Then change PEERDNS to 'no' in the file. For example:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no This option prevents /etc/resolv.conf from being rewritten after a system reboot.

If this method is invalid, add dns information to eth0:

The namesever in the /etc/resolv.conf file is lost after restarting RedHat5 or restarting service network restart. I followed the instructions in the file and added DNS to /etc/sysconfig/network-scripts/ifcfg-eth0 to solve it. But I don't know what exactly rewrites the /etc/resolv.conf file on reboot.

The /etc/resolv.conf file is as follows:

nameserver 59.51.78.210
nameserver 59.51.78.211
nameserver 192.168.0.1
search domain
domain domain
# Generated by NetworkManager

# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:

# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
===============================================
/etc/sysconfig/network-scripts/ ifcfg-eth0 的内容:

# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=08:00:27:cc:64:86
NETMASK=255.255.255.0
IPADDR=192.168.0.155
GATEWAY=192.168.0.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=no

#我在这添加了DNS后,/etc/ resolv.conf文件内容保存下来了
DNS1=202.96.128.86
DNS2=202.96.128.166
DNS3=8.8.8.8

 

 

nds改掉就好了

 

http://blog.csdn.net/fax5201314/article/details/8272518

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326296779&siteId=291194637