您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關linux6重啟后resolv中DNS信息會自動修改的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
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-eth4:IPADDR=192.167.120.11
查看網卡的DNS信息,沒有配置DNS
[root@bsdb ~]# grep DNS /etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network-scripts/ifcfg-eth2:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth3:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth5:PEERDNS=yes
/etc/sysconfig/network-scripts/ifcfg-eth6: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-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
/etc/sysconfig/network-scripts/ifcfg-eth6: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-eth2: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-eth2:DNS1=192.168.30.50
/etc/sysconfig/network-scripts/ifcfg-eth2:DNS2=192.168.130.50
/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
/etc/sysconfig/network-scripts/ifcfg-eth6: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-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
/etc/sysconfig/network-scripts/ifcfg-eth6: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
感謝各位的閱讀!關于“linux6重啟后resolv中DNS信息會自動修改的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。