每次我重启网络时,我的 /etc/resolv.conf 都会被重置

每次我重启网络时,我的 /etc/resolv.conf 都会被重置

这是我/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即使在重新启动时也不会被删除。

答案1

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

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

如果您愿意手动编辑 /etc/sysconfig/network-scripts 目录中的文件,则应该禁用 NetworkManager 服务。

# systemctl status NetworkManager

如果命令返回“active”,那么您应该禁用它。

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

然后你可以编辑/etc/resolv.conf

相关内容