Linux系统resolv.conf配置信息丢失的解决方法
2016-04-25 11:28
579 查看
我要配置DNS,修改/etc/resolv.conf,修改后重启服务 service network restart ,修改/etc/resolv.conf的信息丢失,请大家看看。[code]修改前的配置
# Generated by NetworkManager
search localhost
# 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文件中直接加入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
nameserver 222.46.120.6
方法二:
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了。
方法三:
resolv.conf开头的第一句说明resolv.conf这个文件是由NetworkManager这个程序生成的(对应的是network-manager服务),那么解决办法也就来了:我们关掉network-manager即可,命令为:sudo service network-manager stop或者sudo /etc/init.d/network-manager
stop,但是这种方法不是一劳永逸的,因为每次重启系统后还是会自动启动这个服务,因此我们需要完全禁止network-manager启动即可。编辑network manager的配置文件,使用命令:sudo vi /etc/init/network-manager.conf。注释掉其中的start on部分即可。内容如下:
# network-manager - network connection manager
#
# The Network Manager daemon manages the system's network connections,
# automatically switching between the best available.
description "network connection manager"
#start on (local-filesystems
# and started dbus
# and static-network-up)
stop on stopping dbus
expect fork
respawn
script
# set $LANG so that messages appearing on the GUI will be translated. See LP: 875017
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE LC_MESSAGES LC_ALL
fi
方法四:
前面提到固定IP的上网方式主要是修改/etc/network/interfaces这个文件,配置IP、网关什么的,其实这里面还有个参数可以配置,那就是DNS了,对应的参数名为dns-nameservers,这里设置的优先级比resolv.conf高,也就是网络会从这里读取DNS配置,如果没配置才去看resolv.conf里面的设置,因此在这里面配置DNS更简单。在其后追加
dns-nameservers xxx.xxx.xxx.xxx
# Generated by NetworkManager
search localhost
# 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文件中直接加入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
nameserver 222.46.120.6
方法二:
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了。
方法三:
resolv.conf开头的第一句说明resolv.conf这个文件是由NetworkManager这个程序生成的(对应的是network-manager服务),那么解决办法也就来了:我们关掉network-manager即可,命令为:sudo service network-manager stop或者sudo /etc/init.d/network-manager
stop,但是这种方法不是一劳永逸的,因为每次重启系统后还是会自动启动这个服务,因此我们需要完全禁止network-manager启动即可。编辑network manager的配置文件,使用命令:sudo vi /etc/init/network-manager.conf。注释掉其中的start on部分即可。内容如下:
# network-manager - network connection manager
#
# The Network Manager daemon manages the system's network connections,
# automatically switching between the best available.
description "network connection manager"
#start on (local-filesystems
# and started dbus
# and static-network-up)
stop on stopping dbus
expect fork
respawn
script
# set $LANG so that messages appearing on the GUI will be translated. See LP: 875017
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE LC_MESSAGES LC_ALL
fi
方法四:
前面提到固定IP的上网方式主要是修改/etc/network/interfaces这个文件,配置IP、网关什么的,其实这里面还有个参数可以配置,那就是DNS了,对应的参数名为dns-nameservers,这里设置的优先级比resolv.conf高,也就是网络会从这里读取DNS配置,如果没配置才去看resolv.conf里面的设置,因此在这里面配置DNS更简单。在其后追加
dns-nameservers xxx.xxx.xxx.xxx
相关文章推荐
- (4)Linux常用命令学习
- 判断Linux load的值是否过高
- CentOS6 图形界面(gnome)安装
- linux sort 命令详解
- 4000 linux系统CentOS下调整home和根分区大小的方法
- 一个优化的很不错的sysctl.conf配置分享
- linux下Vim小技巧
- centos6源码编译安装MySQL5.6
- GitLab CE 9-3-stable源码安装手册(Centos6/REHL6)
- CentOS下查看进程和删除进程
- Linux下更新build-tools-20.0.0显示The package filter removed all packages.
- Linux mount挂载目录
- linux修改挂载目录
- linux 挂载硬盘到目录
- centos install pssh
- centos 7 pip yum
- linux下安装Nagios-check-mk-agent
- Linux内核学习总结
- Linux mm_struct基础
- Windows和Linux下Mysql 重置root 密码