Debian 11 修改默认的DHCP分配的服务器

有时在VPS上默认的安装都是用的DHCP分配的地址和DNS服务器,自己又懒得手动去修改网卡配置文件。直接修改resolv.conf这个文件,重启又会被DHCP分配的直接覆盖,这里有个办法永久性更改默认DNS服务器。

nano /etc/resolvconf/resolv.conf.d/head

然后添加自己自定义的外部服务器,比如

nameserver 8.8.8.8
nameserver 8.8.4.4

然后保存,执行以下命令进行更新。

sudo resolvconf --enable-updates
sudo resolvconf -u

这个时候再# cat /etc/resolv.conf 输出的文件已经看到改动成功了,把自定义的服务器添加到头部了。

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "resolvectl status" to see details about the actual nameservers.
nameserver 1.1.1.1
nameserver 8.8.4.4
nameserver 100.100.2.136
nameserver 100.100.2.138

参考链接:https://www.ricmedia.com/tutorials/set-permanent-dns-nameservers-ubuntu-debian-resolv-conf