文档首页> 常见问题> Debian 如何修改DNS,设置DNS?

Debian 如何修改DNS,设置DNS?

发布时间:2023-03-17 21:56       

一、临时设置

直接修改 /etc/resolv.conf,例如直接添加nameserver 8.8.8.8。

注意:系统重启或resolvconf重启后会刷新该配置文件。

二、 永久配置

/etc/resolv.conf是一个链接,指向/run/resolvconf/resolv.conf,/run/resolvconf/resolv.conf的内容是由/etc/resolvconf/resolv.conf.d/base加载过去的。

参考:

①Ubuntu通过修改配置文件进行网络配置及ubuntu解决resolv.conf被重写问题和NetworkManager的关系;

②Debian DNS resolv.conf 重启失效/复写;

 

# 进入/etc/resolvconf/resolv.conf.d/文件夹

cd /etc/resolvconf/resolv.conf.d/

# 添加nameserver,也可以修改head或tail

vi /etc/resolvconf/resolv.conf.d/base

nameserver 8.8.8.8

# 刷新或重启

sudo resolvconf -u

sudo systemctl restart resolvconf

 

注:/etc/resolvconf/run/resolv.conf似乎也是指向/run/resolvconf/resolv.conf的链接,并且/etc/resolvconf/run/interface/systemd-resolved文件也会同时添加到/run/resolvconf/resolv.conf中,如果有大佬知道可以指点一下。

 

# 进入/etc/resolvconf/run/interface/文件夹

cd /etc/resolvconf/run/interface/

# 添加nameserver

vi /etc/resolvconf/run/interface/systemd-resolved

nameserver 8.8.8.8

# 刷新或重启

sudo resolvconf -u

sudo systemctl restart resolvconf