linux6重啟後resolv中DNS資訊會自動修改的理解

lusklusklusk發表於2018-06-21
總結:linux 6的/etc/resolv.conf重啟後修改的原因,是因為重啟時如果NetworkManager服務自動啟動則該服務會讀取網路卡資訊中的NM_CONTROLLED和DNS配置,如果網路卡中配置了NM_CONTROLLED=yes,如果網路卡中配置了DNS則把網路卡中的DNS寫入到resolv.conf,如果網路卡沒有配置DNS則把空的DNS資訊寫入resolv.conf

如果不希望重啟時/etc/resolv.conf被修改,則關閉NetworkManager服務service NetworkManager stop 
chkconfig --level 0123456 NetworkManager off
並修改網路卡NM_CONTROLLED=no



也就是說重啟時,如果有Network Manager服務,且網路卡配置了Network Manager服務,則該服務會根據網路卡的DNS修改/etc/resolv.conf

而網路卡中DNS配置,不需要每個有IP的網路卡都配置,只要其中一個配置了DNS就可以,因為DNS是共享的,但是DNS必須配置在有IP的網路卡上,如果有很多個網路卡但是沒有IP,就算這些網路卡配置了DNS,則重啟後/etc/resolv.conf也不會獲取這個DNS




故障現象1,/etc/resolv.conf裡面設定的nameserver資訊丟失了
[root@bsdb ~]# 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

檢視檔案屬性,發現檔案被修改了
[root@bsdb ~]# ll /etc/resolv.conf
-rw-r--r--. 1 root root 228 6月  19 11:06 /etc/resolv.conf

發現檔案修改時間和重啟時間匹配
[root@bsdb ~]# last |grep reboot
reboot   system boot  2.6.32-431.el6.x Tue Jun 19 11:06 - 11:27 (2+00:20)

檢視網路卡的IP
[root@bsdb ~]# grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0:IPADDR=192.168.21.16
/etc/sysconfig/network-scripts/ifcfg-eth3:IPADDR=192.167.120.11

檢視網路卡的DNS資訊,沒有配置DNS
[root@bsdb ~]# grep DNS  /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth1:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth2:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth4:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth5:PEERDNS=yes

檢視網路卡是否啟用了NetworkManager管理,即NM_CONTROLLED=yes
[root@bsdb ~]# grep NM_CONTROLLED /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth1:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth2:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth3:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth4:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth5:NM_CONTROLLED=yes

檢查NetworkManager是否執行
[root@bsdb ~]# service NetworkManager status
NetworkManager (pid  6297) 正在執行...

OS版本
[oraprod@bsdb ~]$ cat /etc/issue
CentOS release 6.5 (Final)




故障現象2,/etc/resolv.conf裡面設定的nameserver被修改了
[root@lmdb ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.30.50
nameserver 192.168.130.50

檢視檔案屬性,發現檔案被修改了
[root@lmdb ~]# ll /etc/resolv.conf
-rw-r--r--. 1 root root 81 6月  19 11:04 /etc/resolv.conf

發現檔案修改時間和重啟時間匹配
[root@lmdb ~]# last |grep reboot
reboot   system boot  2.6.32-642.el6.x Tue Jun 19 11:04 - 10:09 (1+23:04)

檢視網路卡的IP
[root@lmdb ~]# grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0:IPADDR=192.168.148.200
/etc/sysconfig/network-scripts/ifcfg-eth1:IPADDR=192.168.130.200

檢視網路卡的DNS資訊,配置了DNS,且配置DNS的是有IP的網路卡之一
[root@lmdb ~]# grep DNS /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth1:DNS1=192.168.30.50
/etc/sysconfig/network-scripts/ifcfg-eth1:DNS2=192.168.130.50
/etc/sysconfig/network-scripts/ifcfg-eth1:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth2:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth3:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth4:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth5:PEERDNS=yes

檢視網路卡是否啟用了NetworkManager管理,即NM_CONTROLLED=yes
[root@lmdb ~]# grep NM_CONTROLLED /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth0:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth1:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth2:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth3:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth4:NM_CONTROLLED=yes
/etc/sysconfig/network-scripts/ifcfg-eth5:NM_CONTROLLED=yes

檢查NetworkManager是否執行

[root@lmdb ~]# service NetworkManager status
NetworkManager (pid  3173) 正在執行...

OS版本
[root@lmdb ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2156443/,如需轉載,請註明出處,否則將追究法律責任。

相關文章