resolv.conf 配置信息丢失解决方法
配置DNS,修改/etc/resolv.conf,修改后重启服务 service network restart ,修改/etc/resolv.conf的信息丢失,请大家看看。
[code]修改前的配置
# 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
网上baidu的
解决方法一:在ifcfg-eth0 直接加入DNS1=xxx.xxx.xxx.xxx,再service network restart
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:B5:E4:65"
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.128.133
NETMASK=255.255.255.0
GATEWAY=192.168.128.1
DNS1=222.46.120.6
再来查看resolv.conf 多了一行 namerserver xxx.xxx.xxx.xx
# Generated by NetworkManager
nameserver 222.46.120.6
本人没有测示:
网上baidu的
还有方法二:
文章内容:
vim /etc/resolvconf/resolv.conf.d/head 文件
显示与resolv.conf相同的内容:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN)
在最后键入nameserver 202.102.152.3
保存退出,
resolvconf -u
此时就可以正常上网了,重启后不用在重新设置DNS了。
测示失败: [root@localhost etc]# find / -name resolv.conf.d 找不到这个文件 这是哪个linux版本的配置??
方法三:(自己向别人请教,经测示过的,可用,原理也清晰)
系统环境:
[root@localhost root]# cat /etc/issue CentOS release 6.2 (Final) Kernel \r on an \m [root@localhost root]# uname -a Linux localhost 2.6.32-220.el6.i686 #1 SMP Tue Dec 6 16:15:40 GMT 2011 i686 i686 i386 GNU/Linux
系统平台:
防火墙已开启/iptables:Firewall is running.
SELINUX=enabled
/etc/resolv.conf文件配置好了, service network restart 重启丢失,主要是NetworkManager服务引起的.
1. 修改/etc/resolv.conf 文件 ,添加需要解析的nameserver
[root@localhost root]# cat /etc/resolv.conf # Generated by NetworkManager 备注了,这个是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 nameserver 10.1.32.16 nameservre 8.8.8.8
2.修改 /etc/sysconfig/network-scripts/ifcfg-eth0 文件中的#NM_CONTROLLED改成no
[root@localhost root]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" HWADDR="00:26:9E:27:BF:2F" NM_CONTROLLED="no" #NM_CONTROLLED改成no ONBOOT="yes" IPADDR=10.43.5.30 NETMASK=255.255.255.0 GATEWAY=10.43.5.253
3. 将 NetworkManager 服务停止
[root@localhost root]# service NetworkManager status NetworkManager is stopped [root@localhost xjb]#
[root@localhost root]# chkconfig NetworkManager off
4. 重启一下网络,测示一下
[root@localhost etc]# cat /etc/resolv.conf # 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 nameserver 10.1.32.16 nameservre 8.8.8.8 [root@localhost etc]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ] [root@localhost etc]# cat /etc/resolv.conf # 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
nameserver 10.1.32.16 nameservre 8.8.8.8 search localhost [root@localhost etc]#