Ubuntu 20.04设置DNS解析(解决resolve.conf被覆盖问题)
ubuntu在域名解析时,最直接使用的是/etc/resolve.conf文件,它是/run/systemd/resolve/
resolve.conf的软链接,而对于刚装完的ubuntu系统,该文件的内容如下:
This file is managed by man:systemd-resolved(8). Do not edit.
This is a dynamic resolv.conf file for connecting local clients to the
internal DNS stub resolver of systemd-resolved. This file lists all
configured search domains.
Run "resolvectl status" to see details about the uplink DNS servers
currently in use.
Third party programs must not access this file directly, but only through the
symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
replace this symlink by a static file or a different symlink.
See man:systemd-resolved.service(8) for details about the supported modes of
operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
直接修改/etc/resolv.conf中的nameserver 配置,例如nameserver 192.168.4.2,修改完成后,重启服务会重新还原文件。
解决:
- 修改/etc/systemd/resolved.conf,例如:
[Resolve]
DNS=8.8.8.8 114.114.114.114 192.168.4.2
2.重启域名解析服务
systemctl restart systemd-resolved
systemctl enable systemd-resolved
3.备份当前的/etc/resolve.conf,并重新设置/run/systemd/resolve/resolv.conf 到/etc/resolve.conf的软链接
mv /etc/resolv.conf /etc/resolv.conf.bak
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
4.查看验证,
cat /etc/resolv.conf
重启服务再查看。ping www.baidu.com可以ping通。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下