resolv.conf 与 netplan 配置不匹配

il_*_*mix 3 dns resolv.conf netplan

我正在设置 Ubuntu Server 20.04 系统作为 LAN 和 WAN 之间的网关。我无法正确配置 DNS。

我的 2 个接口有 2 个 netplan 配置文件。

内部 eth 接口 (LAN)

root@gate:~# cat /etc/netplan/01-eth_int.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
        enp4s0:
            addresses: ['10.0.10.1/24']
            match:
                macaddress: 00:60:e0:76:9e:e7
            set-name: eth_int
  version: 2
Run Code Online (Sandbox Code Playgroud)

外部 eth 接口 (WAN)

root@gate:~# cat /etc/netplan/02-eth_ext.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
        enp5s0:
            addresses: ['10.200.56.254/24']
            gateway4: 10.200.56.1
            nameservers:
                addresses: [195.78.215.228, 195.78.223.228]
                addresses: [8.8.8.8, 8.8.4.4]
            match:
                macaddress: 00:60:e0:76:9e:e8
            set-name: eth_ext
  version: 2
Run Code Online (Sandbox Code Playgroud)

重新启动时,接口将根据 netplan 配置文件进行配置。但 /etc/resolv.conf 配置错误

root@gate:~# cat /etc/resolv.conf
# 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
Run Code Online (Sandbox Code Playgroud)

进行的测试/检查:

  • /etc/resolv.conf 是 ../run/systemd/resolve/stub-resolv.conf 的符号链接
  • systemd-resolve --status 返回 eth_ext 接口的正确 DNS,但没有全局 DNS(可能是一个问题?)
    root@gate:~# systemd-resolve --status
    Global
           LLMNR setting: no
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
              DNSSEC NTA: 10.in-addr.arpa
                          16.172.in-addr.arpa
                          168.192.in-addr.arpa
                          17.172.in-addr.arpa
                          18.172.in-addr.arpa
                          19.172.in-addr.arpa
                          20.172.in-addr.arpa
                          21.172.in-addr.arpa
                          22.172.in-addr.arpa
                          23.172.in-addr.arpa
                          24.172.in-addr.arpa
                          25.172.in-addr.arpa
                          26.172.in-addr.arpa
                          27.172.in-addr.arpa
                          28.172.in-addr.arpa
                          29.172.in-addr.arpa
                          30.172.in-addr.arpa
                          31.172.in-addr.arpa
                          corp
                          d.f.ip6.arpa
                          home
                          internal
                          intranet
                          lan
                          local
                          private
                          test

    Link 5 (eth_ext)
          Current Scopes: DNS
    DefaultRoute setting: yes
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
             DNS Servers: 195.78.215.228
                          195.78.223.228
                          8.8.8.8
                          8.8.4.4

    Link 4 (enp0s31f6)
          Current Scopes: none
    DefaultRoute setting: no
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no

    Link 3 (eth_int)
          Current Scopes: none
    DefaultRoute setting: no
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no

    Link 2 (enp3s0)
          Current Scopes: none
    DefaultRoute setting: no
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
Run Code Online (Sandbox Code Playgroud)
  • 编辑/etc/systemd/resolved.conf,设置并取消注释 DNS 条目。全局 DNS 条目显示正在运行 systemd-resolve --status,但 /etc/resolv.conf 不会更改

显然,这种不匹配会阻止 DNS 正常工作

root@gate:~# ping google.com
ping: google.com: Temporary failure in name resolution

root@gate:~#  nslookup heise.de 127.0.0.53
;; connection timed out; no servers could be reached
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

Gry*_*ryu 5

你已经提到过,你的/etc/resolv.conf符号链接是/run/systemd/resolve/stub-resolv.conf

\n

要解决此问题:

\n
    \n
  1. 取消链接:$ sudo unlink /etc/resolv.conf
  2. \n
  3. $ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
  4. \n
  5. sudo systemctl restart systemd-resolved.service
  6. \n
\n

以下信息来自man systemd-resolved

\n
/ETC/RESOLV.CONF\n       Four modes of handling /etc/resolv.conf (see resolv.conf(5)) are supported:\n\n       \xe2\x80\xa2   systemd-resolved maintains the /run/systemd/resolve/stub-resolv.conf file for compatibility with\n           traditional Linux programs. This file may be symlinked from /etc/resolv.conf. This file lists the\n           127.0.0.53 DNS stub (see above) as the only DNS server. It also contains a list of search domains that are\n           in use by systemd-resolved. The list of search domains is always kept up-to-date. Note that\n           /run/systemd/resolve/stub-resolv.conf should not be used directly by applications, but only through a\n           symlink from /etc/resolv.conf. This file may be symlinked from /etc/resolv.conf in order to connect all\n           local clients that bypass local DNS APIs to systemd-resolved with correct search domains settings. This\n           mode of operation is recommended.\n\n       \xe2\x80\xa2   A static file /usr/lib/systemd/resolv.conf is provided that lists the 127.0.0.53 DNS stub (see above) as\n           only DNS server. This file may be symlinked from /etc/resolv.conf in order to connect all local clients\n           that bypass local DNS APIs to systemd-resolved. This file does not contain any search domains.\n\n       \xe2\x80\xa2   systemd-resolved maintains the /run/systemd/resolve/resolv.conf file for compatibility with traditional\n           Linux programs. This file may be symlinked from /etc/resolv.conf and is always kept up-to-date, containing\n           information about all known DNS servers. Note the file format's limitations: it does not know a concept of\n           per-interface DNS servers and hence only contains system-wide DNS server definitions. Note that\n           /run/systemd/resolve/resolv.conf should not be used directly by applications, but only through a symlink\n           from /etc/resolv.conf. If this mode of operation is used local clients that bypass any local DNS API will\n           also bypass systemd-resolved and will talk directly to the known DNS servers.\n\n       \xe2\x80\xa2   Alternatively, /etc/resolv.conf may be managed by other packages, in which case systemd-resolved will read\n           it for DNS configuration data. In this mode of operation systemd-resolved is consumer rather than provider\n           of this configuration file.\n\n       Note that the selected mode of operation for this file is detected fully automatically, depending on whether\n       /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf or lists 127.0.0.53 as DNS server.\n
Run Code Online (Sandbox Code Playgroud)\n