Ubuntu系统下配置DNS
在Ubuntu系统下使用systemd-resolved来管理DNS配置是一个常见的方法。以下是如何配置和使用systemd-resolved的步骤:
检查
systemd-resolved服务状态:
首先,确保systemd-resolved服务正在运行。sudo systemctl status systemd-resolved如果服务没有运行,可以启动并启用它:
sudo systemctl start systemd-resolved sudo systemctl enable systemd-resolved编辑
resolved.conf文件:systemd-resolved的配置文件位于/etc/systemd/resolved.conf。你可以编辑这个文件来设置DNS服务器。sudo vim /etc/systemd/resolved.conf在文件中找到或添加以下行:
[Resolve] DNS=8.8.8.8 8.8.4.4保存并退出Vim。
重启
systemd-resolved服务:
修改配置文件后,需要重启systemd-resolved服务以应用更改。sudo systemctl restart systemd-resolved检查DNS配置:
你可以使用resolvectl命令来检查当前的DNS配置。resolvectl status这将显示当前的DNS服务器和其他相关信息。
确保
resolv.conf指向systemd-resolved:
默认情况下,/etc/resolv.conf应该是一个指向systemd-resolved的符号链接。你可以检查这一点:ls -l /etc/resolv.conf如果
/etc/resolv.conf不是指向/run/systemd/resolve/stub-resolv.conf或/run/systemd/resolve/resolv.conf的符号链接,你可以手动创建或修复它:sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf或者,如果你希望使用完整的DNS配置:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf验证DNS解析:
最后,你可以使用dig或nslookup命令来验证DNS解析是否正常工作。dig example.com或者
nslookup example.com
Ubuntu系统下配置DNS
http://localhost:8080/archives/ubuntuxi-tong-xia-pei-zhi-dns