我一直在创建和销毁虚拟机,以测试各种服务或应用程序,所以我想使用 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 上的系统日志让我完全不知道可能发生了什么:
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
我的猜测是 NSS 库没有配置为在查找主机名时查询 mDNS,因此当程序查找主机名时它会失败(即使 Avahi 本身正在获取名称)。检查
nss-mdns
软件包是否已安装(它似乎只在EPEL中可用,而不是 CentOS 本身),并且 in 中的hosts
行/etc/nsswitch.conf
包含mdns4
(或mdns4_minimal
)数据库。它应该看起来像这样:您可以使用 测试主机名查找
getent hosts <hostname>
。