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 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
我的猜測是 NSS 庫未配置為在查找主機名時諮詢 mDNS,因此當程序查找主機名時它會失敗(即使 Avahi 本身正在獲取該名稱)。檢查
nss-mdns
軟體包是否已安裝(它似乎只在EPEL中可用,而不是 CentOS 本身),並且 in 中的hosts
行/etc/nsswitch.conf
包含mdns4
(或mdns4_minimal
)數據庫。它應該看起來像這樣:hosts: files mdns4_minimal [NOTFOUND=return] dns
您可以使用
getent hosts <hostname>
.