如何设置 systemd-resolved 的搜索路径?

如何设置 systemd-resolved 的搜索路径?

的手册页systemd-resolved.service显示:

systemd-resolved维护/run/systemd/resolve/stub-resolv.conf文件以兼容传统 Linux 程序。此文件可能来自 的符号链接 /etc/resolv.conf。此文件将 127.0.0.53 DNS 存根(见上文)列为唯一 DNS 服务器。它还包含 正在使用的搜索域列表 systemd-resolved。搜索域列表始终保持最新。

(重点是我加的。)“搜索域列表始终保持最新”似乎暗示该列表是从其他地方同步的,但没有说明在哪里。这个搜索域列表来自哪里?具体来说,我该如何修改它?

答案1

在我的 18.04.3 系统上,man solved.conf 建议修改 /etc/systemd/resolved.conf 文件的 Domains= 行。摘录如下:

Domains=
           A space-separated list of domains. These domains are used as search suffixes when resolving single-label host names
           (domain names which contain no dot), in order to qualify them into fully-qualified domain names (FQDNs). Search
           domains are strictly processed in the order they are specified, until the name with the suffix appended is found. For
           compatibility reasons, if this setting is not specified, the search domains listed in /etc/resolv.conf are used
           instead, if that file exists and any domains are configured in it. This setting defaults to the empty list.

           Specified domain names may optionally be prefixed with "~". In this case they do not define a search path, but
           preferably direct DNS queries for the indicated domains to the DNS servers configured with the system DNS= setting
           (see above), in case additional, suitable per-link DNS servers are known. If no per-link DNS servers are known using
           the "~" syntax has no effect. Use the construct "~."  (which is composed of "~" to indicate a routing domain and "."
           to indicate the DNS root domain that is the implied suffix of all DNS domains) to use the system DNS server defined
           with DNS= preferably for all domains.

完成上述操作并重新启动 systemd-resolved 后,我的 /etc/resolv.conf 现在包含我想要的搜索域(因为我已经在这个 Ubuntu 服务器上配置了一个静态地址 - 它不会从 DHCP 中获取任何东西)

答案2

搜索路径由 DHCP 更新。在我的路由器中,此设置称为“域名”。

为了更新搜索路径,我在路由器中设置了域,然后在 Ubuntu 机器上更新了 DHCP 租约(service network-manager restart或重新启动)。

systemd-resolve --status/run/systemd/resolve/stub-resolv.conf然后将把该域显示为“DNS 域”,并且它将作为指令显示search

请注意dig命令/etc/resolv.conf默认情况下不使用搜索列表. 添加+search选项以启用此功能:

dig +search some-hostname

相关内容