linux – 使用avahi连接到主机会出错:名称或服务未知

前端之家收集整理的这篇文章主要介绍了linux – 使用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
error@puppet.local'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主机的输出

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

解决方法

我的猜测是NSS库没有配置为在查找主机名时咨询mDNS,因此当程序查找主机名时它失败(即使Avahi本身正在拿起名字).检查是否已安装 nss-mdns软件包(它似乎仅在 EPEL中可用,而不是CentOS本身),并且/etc/nsswitch.conf中的主机行包含mdns4(或mdns4_minimal)数据库.它应该看起来像这样:
hosts:      files mdns4_minimal [NOTFOUND=return] dns

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

猜你在找的Linux相关文章