![每次我重启网络时,我的 /etc/resolv.conf 都会被重置](https://linux22.com/image/728250/%E6%AF%8F%E6%AC%A1%E6%88%91%E9%87%8D%E5%90%AF%E7%BD%91%E7%BB%9C%E6%97%B6%EF%BC%8C%E6%88%91%E7%9A%84%20%2Fetc%2Fresolv.conf%20%E9%83%BD%E4%BC%9A%E8%A2%AB%E9%87%8D%E7%BD%AE.png)
这是我/etc/resolv.conf
的CentOS 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