使用 avahi 连接到主机时出现错误:名称或服务未知

使用 avahi 连接到主机时出现错误:名称或服务未知

为了测试各种服务或应用程序,我一直在创建和销毁虚拟机,因此我想使用 avahi 通过它们的名称连接到它们,这样我就不必在脑子里浪费宝贵的空间去想明天可能就没用的动态 IP 地址。这似乎并不总是有效。

我目前有两个 CentOS 6.3 虚拟机,都运行 avahi-daemon,但其中一个无法通过其名称访问。

问题机器:

error@underground ~ $ ssh nagios.local
ssh: Could not resolve hostname nagios.local: Name or service not known

工作机:

error@underground ~ $ ssh puppet.local
[email protected]'s password: 

但是我可以在网络上看到它:(地下是我工作的主机)

error@underground ~ $ avahi-browse -at
+    br0 IPv4 puppet                                        SSH Remote Terminal  local
+    br0 IPv4 nagios                                        SSH Remote Terminal  local
+    br0 IPv4 puppet [52:54:00:d0:31:c7]                    Workstation          local
+    br0 IPv4 nagios [52:54:00:93:ec:af]                    Workstation          local
+    br0 IPv4 underground [6c:62:6d:d1:df:ad]               Workstation          local
+ virbr0 IPv4 underground [52:54:00:8e:60:30]               Workstation          local

根据反馈,输出来自getent hosts

error@underground ~ $ getent hosts nagios.local
error@underground ~ $ getent hosts puppet.local
192.168.12.146  puppet.local

在 nagios.local 上,无法访问的虚拟机 avahi-daemon(显然)已安装并正在运行,并且我在防火墙上打了适当的洞:

 pkts bytes target     prot opt in     out     source               destination
   74 15950 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251         state NEW udp dpt:5353 

nagios.local 上的 Syslog 根本不知道会发生什么:

Jul 18 04:24:18 nagios avahi-daemon[1384]: Leaving mDNS multicast group on interface eth0.IPv4 with address 192.168.12.132.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Found user 'avahi' (UID 70) and group 'avahi' (GID 70).
Jul 18 04:24:18 nagios avahi-daemon[1476]: Successfully dropped root privileges.
Jul 18 04:24:18 nagios avahi-daemon[1476]: avahi-daemon 0.6.25 starting up.
Jul 18 04:24:18 nagios avahi-daemon[1476]: WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
Jul 18 04:24:18 nagios avahi-daemon[1476]: Successfully called chroot().
Jul 18 04:24:18 nagios avahi-daemon[1476]: Successfully dropped remaining capabilities.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Loading service file /services/ssh.service.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.12.132.
Jul 18 04:24:18 nagios avahi-daemon[1476]: New relevant interface eth0.IPv4 for mDNS.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Network interface enumeration completed.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Registering new address record for 2001:db8:1600:80bf:5054:ff:fe93:ecaf on eth0.*.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Registering new address record for 192.168.12.132 on eth0.IPv4.
Jul 18 04:24:18 nagios avahi-daemon[1476]: Registering HINFO record with values 'X86_64'/'LINUX'.
Jul 18 04:24:19 nagios avahi-daemon[1476]: Server startup complete. Host name is nagios.local. Local service cookie is 3129794608.
Jul 18 04:24:19 nagios avahi-daemon[1476]: Service "nagios" (/services/ssh.service) successfully established.

这两个安装之间的主要区别在于 puppet.local 是作为“桌面”安装的,而 nagios.local 是作为“最小”安装的,并且稍后安装了各种与 avahi 相关的包。

我不知道为什么我无法解析这台机器的名称。我错过了什么显而易见的事情?

更新:根据 mgorven 的建议,我再次检查了主机,发现它没有nss-mdns安装。所以我安装了它,现在问题正好相反!从主机上看:

error@underground ~ $ getent hosts puppet.local
error@underground ~ $ getent hosts nagios.local
192.168.12.132  nagios.local

答案1

我猜想 NSS 库未配置为在查找主机名时咨询 mDNS,因此当程序查找主机名时会失败(即使 Avahi 本身正在获取该名称)。检查nss-mdns软件包已安装(似乎只适用于电力供应处(而不是 CentOS 本身),并且hosts中的行/etc/nsswitch.conf包含mdns4(或mdns4_minimal)数据库。它应该看起来像这样:

hosts:      files mdns4_minimal [NOTFOUND=return] dns

您可以使用 测试主机名查找getent hosts <hostname>

相关内容