Netplan DNS 灾难

Netplan DNS 灾难

我正在努力让 netplan 工作。(我以为我仍然需要 resolv.conf,它确实修复了 DNS,但在重启时会被重写。)一切似乎都正确,但我无法 ping。

$ sudo netplan --debug apply
** (generate:14256): DEBUG: 00:38:22.887: Processing input file /etc/netplan/50-cloud-init.yaml..
** (generate:14256): DEBUG: 00:38:22.888: starting new processing pass
** (generate:14256): DEBUG: 00:38:22.888: We have some netdefs, pass them through a final round of validation
** (generate:14256): DEBUG: 00:38:22.888: ens160: setting default backend to 1
** (generate:14256): DEBUG: 00:38:22.888: Configuration is valid
** (generate:14256): DEBUG: 00:38:22.888: Generating output files..
** (generate:14256): DEBUG: 00:38:22.888: NetworkManager: definition ens160 is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:ens160 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    ens160:
      critical: true
      dhcp4: true
      dhcp4-overrides:
        use-dns: false
      dhcp6: true
      dhcp6-overrides:
        use-dns: false
      ipv6-privacy: true
      nameservers:
        addresses:
        - 10.10.11.200
        - 1.1.1.1
        search:
        - home
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device ens160 operstate is up, not changing
DEBUG:Skipping non-physical interface: docker0
DEBUG:Skipping non-physical interface: hassio
DEBUG:Skipping non-physical interface: vethecdde1c
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens160
DEBUG:netplan triggering .link rules for docker0
DEBUG:netplan triggering .link rules for hassio
DEBUG:netplan triggering .link rules for vethecdde1c
$ ping google.com
ping: google.com: Temporary failure in name resolution

根据请求进行编辑。

我以为我正在使用 netplan,因为它已经安装好了。

/etc/netplan/50-cloud-init.yaml 我没有创建这个文件,它在那里。

network:
    ethernets:
        ens160:
            critical: true
            dhcp4: true
            dhcp4-overrides:
                use-dns: false
            dhcp6: true
            dhcp6-overrides:
                use-dns: false
            ipv6-privacy: true
            nameservers:
                search: [home]
                addresses: [10.10.11.200, 1.1.1.1]

    version: 2

当我尝试这两个命令时,两个命令都出现错误。

$ sudo systemd-resolve --status
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.
$ sudo resolvectl --status
sudo: resolvectl: command not found

答案1

你想要的是 Dnsmasq。Netplan 仅允许配置后备 DNS,而不是域 DNS。

准备安装

  • 删除“systemd-resolved”
    • sudo systemctl disable systemd-resolved
    • sudo systemctl stop systemd-resolved
  • 删除链接的 resolv.conf
    • 确保它是一个链接(将指向类似:...systemd/resolve/stub-resolv.conf):
    • sudo ls -lh /etc/resolv.conf
    • 移除链接:
    • sudo rm /etc/resolv.conf
  • 添加临时 DNS
    • sudo echo "nameserver 8.8.8.8" > /etc/resolv.conf
  • 安装 Dnsmasq
    • sudo apt update
    • sudo apt install dnsmasq

dnsmasq.d/lxd 的问题

dnsmasq首次启动时您可能会收到此错误:

dnsmasq:无法访问 /etc/dnsmasq.d/lxd:没有此文件或目录

要解决这个问题,只需删除符号链接 ¯\(ツ)

sudo rm /etc/dnsmasq.d/lxd

并重新启动:

service dnsmasq restart
service dnsmasq status

配置 DNSmasq

编辑/etc/dnsmasq.conf

搜索并取消注释此选项:

  • 需要域
  • bogus-priv
  • 严格顺序
  • 无解决

添加您的域名 DNS 服务器,例如:

server=/mycompany.com.pl/192.168.0.123
server=/some.vlan/10.234.0.123

添加通用服务器例如:

server=1.1.1.1
server=8.8.4.4

完成后重新启动:

service dnsmasq restart
service dnsmasq status

请注意,状态将显示实际使用了哪些 DNS 服务器(using nameserver ...)。

最后步骤

  • 将 DNS 设置为本地:
    • 在解析中添加本地DNS:
      • sudo echo "nameserver 127.0.0.1" > /etc/resolv.conf
    • 也更新/etc/netplan/yaml 文件。
  • dig(或ping)进行测试。
    • (寻找;; ANSWER SECTION:
    • dig app01.some.vlan
    • dig server.mycompany.com.pl
  • 启用开机运行:
    • systemctl enable dnsmasq

相关内容