Ubuntu系统下配置DNS

在Ubuntu系统下使用systemd-resolved来管理DNS配置是一个常见的方法。以下是如何配置和使用systemd-resolved的步骤:

  1. 检查systemd-resolved服务状态:
    首先,确保systemd-resolved服务正在运行。

    sudo systemctl status systemd-resolved

    如果服务没有运行,可以启动并启用它:

    sudo systemctl start systemd-resolved
    sudo systemctl enable systemd-resolved
  2. 编辑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。

  3. 重启systemd-resolved服务:
    修改配置文件后,需要重启systemd-resolved服务以应用更改。

    sudo systemctl restart systemd-resolved
  4. 检查DNS配置
    你可以使用resolvectl命令来检查当前的DNS配置。

    resolvectl status

    这将显示当前的DNS服务器和其他相关信息。

  5. 确保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
  6. 验证DNS解析
    最后,你可以使用dignslookup命令来验证DNS解析是否正常工作。

    dig example.com

    或者

    nslookup example.com


Ubuntu系统下配置DNS
http://localhost:8080/archives/ubuntuxi-tong-xia-pei-zhi-dns
作者
Administrator
发布于
2024年07月23日
许可协议