为什么本机程序可以解析 mDNS 名称而 Nix 程序却无法解析?

为什么本机程序可以解析 mDNS 名称而 Nix 程序却无法解析?

我的本机程序(在 Fedora 上)能够解析 mDNS / Avahi / zeroconf 名称,如下所示:

$ ping felonyspork.local -c 1  
PING felonyspork.local (192.168.88.169) 56(84) bytes of data.
64 bytes from 192.168.88.169 (192.168.88.169): icmp_seq=1 ttl=64 time=1.73 ms

--- felonyspork.local ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.734/1.734/1.734/0.000 ms

$ ssh felonyspork.local        
Last login: Mon Apr 25 16:05:34 2022 from 192.168.88.200

$ exit
Connection to felonyspork.local closed.

但是,我在 Nix 上安装的程序不是:

$ nix-shell -p openssh ssh-tools

[nix-shell:~/src/nixconfig]$ ssh-ping -c 1 felonyspork.local
SSHPING felonyspork.local

--- felonyspork.local ping statistics ---
1 requests transmitted, 0 requests received, 100% request loss

[nix-shell:~/src/nixconfig]$ ssh felonyspork.local
ssh: Could not resolve hostname felonyspork.local: Name or service not known

我已在以下位置配置了 mDNS /etc/nsswitch.conf

hosts:      files myhostname mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns

并且avahi-daemon正在我的系统上运行。

如何让 Nix 程序正确解析 mDNS 名称?这一点尤其重要,因为使用 Morph 进行部署需要有效的 Nix SSH 会话。

答案1

这里缺少的环节是nscd;只需安装nscd并启动守护进程就可以使 Nix 安装的程序运行。

$ sudo dnf install nscd
$ sudo systemctl start nscd.service
$ nix-shell -p ssh-tools

[nix-shell:~]$ ssh-ping felonyspork.local
SSHPING felonyspork.local
Pong from felonyspork.local: ssh_seq=1 time=2191 ms
Pong from felonyspork.local: ssh_seq=2 time=1310 ms
^C
--- felonyspork.local ping statistics ---
2 requests transmitted, 2 requests received, 0% request loss

相关内容