解决 DNS配置 /etc/resolv.conf 重启还原

vps.dance 2022-06-09 2022-07-12 1497℃

/etc/resolv.conf 介绍

/etc/resolv.conf是DNS配置文件, 用于设置DNS服务器的IP地址及DNS域名, 还包含了主机的域名搜索顺序.

编辑 /etc/resolv.conf, 内容比如

nameserver 8.8.8.8
nameserver 1.1.1.1

发现重启后, 内容还原了.

方式1 改成只读 (root用户)

chattr +i /etc/resolv.conf 让文件只读
如果想再次编辑, 可以执行 chattr -i /etc/resolv.conf
Centos应该这步就够了.

方式2 卸载 resolvconf 包 (root用户)

Debian/Ubuntu: apt remove resolvconf 然后reboot重启.
应该只需要这步, resolv.conf就不会还原了.
PS: resolvconf 包会阻止resolv.conf的属性被chattr命令修改.

标签: none

非特殊说明, 所有文章均为原创.