0

I am having difficulty in ssh-ing into Raspberry Pis via their mDNS (avhai / zeroconf) .local host names.

After reboot I can ssh into a pi as expected:

$ ssh user@raspberrypi.local

However after a period of time (it seems to be a day or two - but I've not measured it accurately) I can no-longer access the Pi's via their ".local" URI (ssh, ping, HTTP access, etc. all fail to connect); but I can still access the pi's via their IP addresses (e.g. $ ssh user@192.168.1.100). A reboot of the Pi restores the previous mDNS .local host name.

This effects multiple Pi's (both Pi 3 & 4); and it happens with both WiFi and ethernet connections.

I'm running Raspbian / Raspberry Pi OS on the Pi's; and networking via OpenWRT on Linksys hardware.

Any ideas?

  • 1
    Rather than reboot try sudo systemctl restart avahi-daemon. – Dougie Aug 5 at 19:20
  • That works perfectly @Dougie… Still not sure why avahi is falling over – but restarting it is a much preferable fix than a full reboot. Thankyou! – AJ Poulter Aug 10 at 13:32
1

Occasionally caching prevents Zero-conf resolution and the only cure I have found is to restart all network devices although pinging sometimes refreshes the arp cache.

You may be interested in the following script I use. This falls back to a reserved IP Address if Zero-conf fails.

#!/bin/bash
# script to start ssh connection to Pi
# If not found use default ADDRESS
# 2019-07-30

TARGET="MilliwaysPi4.local"
ADDRESS="10.1.2.84"     # WiFi
ADDRESS2="10.1.2.74"    # Ethernet

ping -c1 $TARGET > /dev/null 2>&1
rc1=$?
if [ $rc1 -gt 0 ]; then
    echo "Can't ping $TARGET"
    TARGET=$ADDRESS
    ping -c1 $TARGET > /dev/null 2>&1
    rc2=$?
    if [ $rc2 -gt 0 ]; then
        TARGET=$ADDRESS2
    fi
fi

if [ $# -eq 0 ] ; then
    USR='pi'
else
    USR=$1
fi

ssh $USR@$TARGET
PS1='\h:\W \u\$ '
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.