1. 程式人生 > >CentOS7經常發現DNS配置失效,配置信息被清空

CentOS7經常發現DNS配置失效,配置信息被清空

spa device manager fatal -s some toc onf 發現

問題描述:

使用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
[root@DB4 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
search leaderment.com
nameserver 192.168.1.253
nameserver 192.168.1.254
[root@DB4 ~]# 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


CentOS7經常發現DNS配置失效,配置信息被清空