即使 avahi-resolve-host-name 成功,也无法使用 getent 解析 .local 域

Unable to resolve .local domains with getent even though avahi-resolve-host-name succeeds

正在尝试使用 CUPS 设置网络打印机。

遵循在线文档说明:

To discover or share printers using DNS-SD/mDNS, setup .local hostname resolution with Avahi and restart cups.service.

按照说明将 Avahi 设置到 avahi-browse --all --ignore-local --resolve --terminateavahi-resolve-host-name my-domain.local 都能正常工作的地步。

但是getent hosts my-domain.local无法解析。这导致 CUPS 无法打印,因为它找不到 my-printer.local.

我阅读了 mdns Github 页面,看到一条注释让我觉得我不需要 /etc/mdns.allow 文件。

nss-mdns has a simple configuration file /etc/mdns.allow for enabling name lookups via mDNS in other domains than .local.

Note: The "minimal" version of nss-mdns does not read /etc/mdns.allow under any circumstances. It behaves as if the file does not exist.

In the recommended configuration, no /etc/mdns.allow file is present.

但后来我看到了那个部分的最后一个注释:

If, during a request, the system-configured unicast DNS (specified in /etc/resolv.conf) reports an SOA record for the top-level local name, the request is rejected. Example: host -t SOA local returns something other than Host local not found: 3(NXDOMAIN). This is the unicast SOA heuristic.

我在我的机器上测试了它,果然,我得到了 Host local not found... 以外的东西。

添加一个包含 .local..local 行的 /etc/mdns.allow 文件,现在我可以 ping my-printer.local.