Trouble using ssh and Avahi

Solved: make sure that libnss-mdns is installed!

I'm having trouble using SSH'ing from my netbook to my desktop using a .local hostname. Every so often, I have to reset the router I use, which resets the addresses it give out to my devices, so a while ago I set up Avahi to get around this*. The /etc/avahi/services/ssh.service file is the standard one copied from the documentation:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<!-- See avahi.service(5) for more information about this configuration file -->
<service-group>
    <name replace-wildcards="yes">%h</name>
       <service>
            <type>_ssh._tcp</type>
            <port>22</port>
       </service>
 </service-group>

This used to work fine, but now for some reason when I try to ssh from my netbook to my desktop, I get the following error message (note I changed my pc's hostname in this output):

user@netbook>> ssh pc.local -vvv
OpenSSH_6.2p2 Ubuntu-6ubuntu0.3, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /home/username/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
ssh: Could not resolve hostname pc.local: Name or service not known

I can ssh from my netbook to my PC when I put in the IP address manually, and when I've set up /etc/hosts correctly (so the daemon on my PC is working fine), it only stops working when I try to use the .local address. SSH'ing in the other direction (PC->netbook) works fine, even when using a .local hostname. Avahi also appears to be working fine:

user@netbook>> avahi-browse -a -t+  
+  wlan0 IPv6 netbook                                  SSH Remote Terminal       local
+  wlan0 IPv6 netbook [<MAC address>]       Workstation                       local
+  wlan0 IPv6 netbook                                  Remote Disk Management local
+  wlan0 IPv4 netbook                                  SSH Remote Terminal       local
+  wlan0 IPv4 netbook [<MAC address>]       Workstation                       local
+  wlan0 IPv4 netbook                                  Remote Disk Management local
+  wlan0 IPv4 pc                                          SSH Remote Terminal       local
+  wlan0 IPv4 pc [<MAC address>]               Workstation                       local
+  wlan0 IPv4 pc                                          Remote Disk Management local
+  wlan0 IPv6 pc                                          SSH Remote Terminal       local
+  wlan0 IPv6 pc [<MAC address>]               Workstation                      local
+  wlan0 IPv6 pc                                          Remote Disk Management local

The netbook is running Lubuntu 13.10; note that I did change to Lubuntu recently, and I only recall seeing this error with Lubuntu and not with plain Ubuntu. My desktop is running Ubuntu 13.10.

Any help would be appreciated!

*I am aware that can set up my router to permanently give set addresses to both devices, and I will do that if I can't resolve this issue, but I'd prefer to try and fix this rather than work around it.

ETA: Pinging the PC from the netbook with the .local hostname doesn't work (unknown host) .

Edit 2: Contents of /etc/nsswitch.conf

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd:         compat
group:          compat
shadow:         compat
hosts:          files mdns4_minimal dns [NOTFOUND=return] mdns4
networks:       files
protocols:      db files
services:       db files
ethers:         db files
rpc:            db files
netgroup:       nis

Well, *.local are not resolved.

So on Client machine (Notebook)

  1. Install avahi-dnsconfd

    sudo apt-get install avahi-daemon avahi-dnsconfd avahi-discover avahi-utils
    

    avahi-dnsconfd listens to the publishing and passes them to resolvconf.

  2. Install libnss-mdns (This library was missing, Installing it fixed the problem in this case)

    sudo apt-get install libnss-mdns
    

    nss-mdns is a plugin for the GNU Name Service Switch (NSS) functionality of the GNU C Library (glibc) providing host name resolution via Multicast DNS (using Zeroconf, aka Apple Bonjour / Apple Rendezvous ), effectively allowing name resolution by common Unix/Linux programs in the ad-hoc mDNS domain .local

  3. Check /etc/nsswitch.conf

    hosts:     files wins mdns4_minimal dns [NOTFOUND=return] mdns4
    

    It should have mdns4_minimal or mdns4 before [NOTFOUND=return] and before dns if you have a DNS server that configured resolve *.local.

    Remove wins if you are not using winbind/samba to resolve Windows share hostnames.

  4. Reboot


Debuging hints:

  • Client machine (Notebook)

    1. Check avahi-dnsconfd service status

      $ service avahi-dnsconfd status
      avahi-dnsconfd start/running, process 1548
      
    2. Run avahi-discover, Your desktop should be listed in IPv4→local→Workstation

      Example in screenshot mx5 is my PC where salah-Aspire-5738 is an other machine.

      enter image description here

    3. See if Avahi can resolve host names

      avahi-resolve -4 --name yourdesktop.local
      
    4. Ping test

      $ ping salah-Aspire-5738.local
      PING salah-Aspire-5738.local (192.168.1.3) 56(84) bytes of data.
      64 bytes from salah-Aspire-5738.local (192.168.1.3): icmp_seq=1 ttl=64 time=2.69 ms
      
  • Server machine (Desktop), In case avahi-discover in Client machine did not list Server entry.

    1. Confirm that avahi-daemon is installed

      sudo apt-get install avahi-daemon avahi-dnsconfd avahi-discover avahi-utils
      

      avahi-daemon provide services publishing.

    2. Check its service status

      $ service avahi-daemon status
      avahi-daemon start/running, process 1517
      
    3. By default avahi publish _workstation._tcp service. check using avahi-discover locally, if not listed try enabling it in /etc/avahi/avahi-daemon.conf (remove #)

      publish-workstation=yes
      

      Then restart daemon:

      sudo service avahi-daemon restart
      

      Check again.