ubuntu设置DNS服务.md
思路
Ubuntu 使用 /etc/resolve.conf
文件进行域名解析,该文件通常是 /run/systemd/resolve/resolv.conf
的软链接。直接编辑 /etc/resolve.conf
是不正确的,因为文件顶部有明确指示不要编辑,并且这些更改可能会被覆盖。
方法
- 编辑
/etc/systemd/resolved.conf
文件:在[Resolve]
部分添加所需的 DNS 服务器地址,例如DNS=8.8.8.8 114.114.114.114
。 - 重启域名解析服务:使用命令
systemctl restart systemd-resolved
和systemctl enable systemd-resolved
来重启和启用服务。 - 备份并重建软链接:备份
/etc/resolve.conf
文件,并设置/run/systemd/resolve/resolv.conf
到/etc/resolve.conf
的新软链接。
工具
- systemd-resolved:用于管理域名解析服务。
- 命令行工具:如
systemctl
,mv
,ln
等,用于执行服务操作和文件操作。
技巧
- 在修改 DNS 设置时,确保正确编辑
resolved.conf
而非resolv.conf
。 - 重启服务和重新链接文件是关键步骤,以确保更改生效。
- 进行更改后,检查
/etc/resolv.conf
确认 DNS 地址已正确更新。
ubuntu设置DNS服务.md
https://abrance.github.io/2023/11/13/mdstorage/domain/linux/ubuntu设置DNS服务/