I have a Raspberry Pi configured with mDNS that is connected to my home LAN (WiFi).

I can ssh into it using sshpass -p raspberry ssh [email protected] only some times. The problem seems intermittent and I am not sure what is wrong with either my laptop setup or the WiFi setup.

These commands work only half of the times:

avahi-resolve-host-name raspberrypi.local
ping -c 5 raspberrypi.local

They show error messages like:

# avahi
Failed to resolve host name 'raspberrypi.local': Timeout reached
ssh: Could not resolve hostname raspberrypi.local: Name or service not known
# ping
ping: raspberrypi.local: Name or service not known

Whereas this command always finds my Raspberry Pi - I can recognize the IP address in the output:

# I found MY_GATEWAY_IP with "ip route | grep default | awk '{ print $$3 }'"
nmap -O -sS -F ${MY_GATEWAY_IP}/24

My laptop configuration file /etc/nsswitch.conf contains this entry:

hosts:          files dns mdns4_minimal

So I think I should always be able to resolve my Raspberry Pi via mDNS.

How can I make sure raspberrypi.local always works?

1 Answer 1


I think you are mixing up some things. The nmap always works because you are scanning the /24 network, which is different than the mDNS resolution. The question is the PI getting different IP's via wifi? If so maybe that's the problem. The super easiest solution is to just static IP the PI and stick it's address in you hosts file. Or do you want to see why mDNS isn't working?

  • 1
    The Pi has the same IP while up, but I can not connect to it all the times. The router is using DHCP so I can not be sure the Pi gets always the same IP. I like relying on raspberry.local because I don't need to deal with IP addresses and it comes already configured in the default settings of the Pi.
    – TPPZ
    Oct 11, 2020 at 8:29
  • I would look in the router log and check for the mac address of the PI to see if it was getting the same IP. As well maybe even more importantly is anything being put in DNS on the router automatically? Since your host file looks for DNS before mDNS perhaps it's caching the worng address. Oct 11, 2020 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .