问题描述:
使用CentOS7后,经常发现/etc/resolv.conf下的永久配置DNS信息不再那么好使,添加的nameserver 192.168.1.xxx的信息在重启或者是重启网卡后偶尔会自动消失
解决办法:
通过上面的注解可以看出,DNS可以通过/etc/sysconfig/network-scripts/目录下的网卡配置文件来添加,添加格式如下:
DNS1=xxx.xxx.xxx.xxx
DNS2=xxx.xxx.xxx.xxx
DOMAIN=lab.foo.com bar.foo.com
所有CentOS7以后,DNS配置信息是直接添加到网卡配置文件当中,不再是添加到/etc/resolv.conf。正确的添加案例如下:
DEVICE=lo IPADDR=127.0.0.1 NETMASK=255.0.0.0 NETWORK=127.0.0.0 # If you're having problems with gated making 127.0.0.0/8 a martian, # you can change this to something else (255.255.255.255, for example) BROADCAST=127.255.255.255 ONBOOT=yes NAME=loopback NM_CONTROLLED=no [[email protected] ~]# cat /etc/resolv.conf # Generated by NetworkManager search leaderment.com nameserver 192.168.1.253 nameserver 192.168.1.254 [[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="no" IPV6_AUTOCONF="no" IPV6_DEFROUTE="no" IPV6_PEERDNS="no" IPV6_PEERROUTES="no" IPV6_FAILURE_FATAL="no" NAME="eth0" UUID="229ff2c7-3c28-4736-9304-d6fe11f7c275" DEVICE="eth0" ONBOOT="yes" IPADDR=192.168.1.90 NETMASK=255.255.255.0 GATEWAY=192.168.1.3 DNS1=192.168.1.253 DNS2=192.168.1.254 DOMAIN=hbgslz.com
原文地址:http://blog.51cto.com/hbgslz/2071644
时间: 2024-10-30 22:03:48