Systemd-networkd:如何将静态名称服务器条目添加到 DHCP 发现的名称服务器?

run*_*niq 9 networking linux dns dhcp systemd

我在 Arch Linux 上使用 systemd 213,并且 systemd-networkd/resolved with DHCP 连接到互联网。我还在 127.0.0.1 上运行缓存 DNS 服务器。我想让这个服务器成为列表中的第一个 DNS 服务器,但我也想使用 systemd-resolved 发现的名称服务器。使用静态 resolv.conf 是不可能的,因为我连接到具有不同 DNS 设置的网络。

我知道我可以设置备用DNS服务器/etc/systemd/resolved.conf,但有与systemd-networkd的方式预先考虑我的本地DNS服务器,那些DHCP发现的?


编辑:到目前为止我尝试过的

  • DNS.network文件中添加一个手动条目会导致该条目被附加而不是前置:

    # This file is managed by systemd-resolved(8). Do not edit.
    #
    # Third party programs must not access this file directly, but
    # only through the symlink at /etc/resolv.conf. To manage
    # resolv.conf(5) in a different way, replace the symlink by a
    # static file or a different symlink.
    
    nameserver 141.48.3.51
    nameserver 141.48.3.17
    nameserver 141.48.3.3
    # Too many DNS servers configured, the following entries may be ignored
    nameserver 127.0.0.1
    
    Run Code Online (Sandbox Code Playgroud)
  • 如果我UseDNS=true也在该[DHCPv4]部分添加,如systemd.network(5), 联机帮助页中所述,DHCP 发现的名称服务器将被忽略,并且使用静态 DNS 条目,这也不是我想要的:

    # This file is managed by systemd-resolved(8). Do not edit.
    #
    # Third party programs must not access this file directly, but
    # only through the symlink at /etc/resolv.conf. To manage
    # resolv.conf(5) in a different way, replace the symlink by a
    # static file or a different symlink.
    
    nameserver 127.0.0.1
    
    Run Code Online (Sandbox Code Playgroud)
  • 使用 in_addr 表示 DNS 地址只是附加我的名称服务器,就像使用正常表示一样。

Mar*_*iae 3

您是否尝试过添加这两行:

  [Network]
  DNS=127.0.0.1
Run Code Online (Sandbox Code Playgroud)

到文件之一/etc/systemd/network/*.network?例如,对于 dhcp 客户端,修改 /etc/systemd/network/80-dhcp.network 以包含以下行:

  [Match]
  Name=en*

  [Network]
  DHCP=yes
  DNS=127.0.0.1
Run Code Online (Sandbox Code Playgroud)

编辑:

您尝试过 in_addr 表示吗?尝试用 16777343 替换 127.0.0.1。