临时修改

直接编辑/etc/resolv.conf文件

生成钩子阻止DHCP修改resolv.conf

只适用于Debian/Ubuntu

编辑/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
添加

1#!/bin/sh
2make_resolv_conf(){
3    :
4}

给文件 nodnsupdate 添加可执行权限

1chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

重启系统,现在你就可以修改 /etc/resolv.conf 文件而且不会担心被回滚了。

写保护锁定resolv.conf文件

1rm -f /etc/resolv.conf
2editor /etc/resolv.conf
3
4#填写上指定的DNS服务器:
5nameserver 1.1.1.1
6nameserver 1.0.0.1
7
8chattr +i /etc/resolv.conf

此时resolv.conf文件的内容就会被锁定不会被重启覆盖,想要解锁的话运行:

1chattr -i /etc/resolv.conf

转载自:https://zhucaidan.xyz/2021/01/419/