Linux

每次我重新啟動網路時,我的 /etc/resolv.conf 都會被重置

  • October 9, 2018

這是我/etc/resolv.confCentOS 7上的:

# Generated by NetworkManager
search example.com
nameserver 10.0.2.3
~                   

這是我的 /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=dhcp
DEFROUTE="yes"
ONBOOT="yes"
TYPE=Ethernet
PERSISTENT_DHCLIENT="yes"
ZONE=public
DNS="192.168.33.11"
PROXY_METHOD=none
BROWSER_ONLY=no
IPADDR=192.168.33.11
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03

systemctl restart network每當我在添加後嘗試重新啟動網路時,nameserver 192.168.33.11它都會重置為上面的網路。我應該進行哪些更改,ifcfg-eth0以便我的新nameserver設備即使在重新啟動時也不會被刪除。

# echo "PEERDNS=no" >>  /etc/sysconfig/network-scripts/ifcfg-eth0

可以防止 DHCP 覆蓋 /etc/resolv.conf

如果您喜歡手動編輯 /etc/sysconfig/network-scripts 目錄中的文件,您應該禁用 NetworkManager 服務。

# systemctl status NetworkManager

如果命令返回“活動”,那麼您應該禁用它。

# systemctl stop NetworkManager.service
# systemctl disable NetworkManager.service
# systemctl restart network.service
# systemctl enable network.service

然後你可以編輯/etc/resolv.conf

引用自:https://serverfault.com/questions/934641