我在 Linux (ubuntu) 桌面上解析 .local 主机时遇到一个奇怪的问题。 (我注意到,因为我的打印机停止工作。我发现打印机的 IP 地址是使用 mdns 解析的,但它不起作用。)然后我尝试 ping 另一台计算机。结果是:
ping: zoe.local: Name or service not known
avahi-browse 能够解析 IP 地址
= enp0s31f6 IPv4 zoe [xx:xx:xx:xx:xx:xx] Workstation local
hostname = [zoe.local]
address = [192.168.3.221]
port = [9]
txt = []
然后我检查了内容/etc/nsswitch.conf
。看起来很正常。
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: compat systemd
group: compat systemd
shadow: compat
gshadow: files
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname mymachines
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
/etc/resolv.conf 是 /run/resolvconf/resolv.conf 的符号链接,内容似乎是标准的:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
search intern
libnss-mdns 也已安装。
在同一网络中的第二台机器上,.local 地址解析工作正常。然后我用 strace 比较了这两个 ping 命令。我发现systemd-resolved的结果是不同的。我捕获了环回接口的流量。有趣的是,systemd-resolvd 报告了 .local 域的 SOA。在下一步中,地址解析会向我的路由器询问 .local 地址。这会导致上述错误。
Wireshark 捕获显示:
1 0.000000000 127.0.0.1 127.0.0.53 DNS 65 Standard query 0x70d2 SOA local
2 0.001437 127.0.0.53 127.0.0.1 DNS 113 Standard query response 0x459c SOA local SOA router.intern
我的第二台机器本地 systemd 解析器不报告 SOA,并且 mdns 地址解析运行良好。
1 0.000000000 127.0.0.1 127.0.0.53 DNS 65 Standard query 0x70d2 SOA local
2 0.027250385 127.0.0.53 127.0.0.1 DNS 65 Standard query response 0x70d2 No such name SOA local
我尝试刷新 dns 缓存,systemd-resolve --flush-caches
但没有什么区别。
systemd-resolvd 的行为似乎很奇怪。有谁知道这里出了什么问题?为什么用 SOA 来解决 systemd 解决的问题?
systemd-resolve --status
在我看来很好:
Global
LLMNR setting: no
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Domain: intern
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 6 (vmnet8)
Current Scopes: none
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Link 5 (vmnet1)
Current Scopes: none
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Link 4 (virbr0-nic)
Current Scopes: none
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Link 3 (virbr0)
Current Scopes: none
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Link 2 (enp0s31f6)
Current Scopes: DNS
DefaultRoute setting: yes
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 192.168.3.1
DNS Servers: 192.168.3.1
fe80::2a0:57ff:fe24:94c9
DNS Domain: ~.
intern
答案1
更新:
我发现了以下问题:https://github.com/lathiat/nss-mdns/issues/75
我的路由器/ISP 为 .local 域提供 SOA。阻止unicast SOA heuristic
mdns 解析。我添加了/etc/mdns.allow
以下内容:
.local.
.local
切换到 mdns4 而不是 mdns4_minimal 后,它可以工作。
hosts: files mdns4 [NOTFOUND=return] dns myhostname mymachines