Raspberry Pi Wifi Avahi mDNS configuration

Background

Avahi mDNS allows connecting to the Raspberry Pi (or other Avahi-enabled device) without knowing the IP address. For the Raspberry Pi, the default address is raspberrypi.local. If you have changed the hostname of your Raspberry Pi as seen from

hostname

joespi

Then in that example, you’d do

ssh [email protected]

instead of the default

ssh [email protected]

As always, you should be using SSH Public Key Authentication with ED25519 keys. Raspberry Pi is trivial to hack like any other device on any operating system if proper cybersecurity is not used. Why do you care if someone hacks your Pi? The hacker can use the Pi’s relatively powerful CPU & GPU to stage sophisticated attacks on the rest of your network.

Setup Avahi mDNS for Wifi-connected host

For a Raspberry Pi or other SSH server on Wifi, the default /etc/avahi/avahi-daemon.conf puts mDNS on all active interfaces. If for some reason you need to manually configure the interfaces Avahi is on, here’s how. This example is for a Raspberry Pi 3 with Raspbian, but will be very similar for many Linux devices.

  1. find your Pi’s hostname

     hostname the default is `raspberrypi`
    
  2. Try to ping your Avahi device from your laptop

     ping raspberrypi.local
    

    if this doesn’t work and you’re on a Windows PC, note that as of this writing, WSL does not yet support Avahi/mDNS. So you would need to use a native Linux or Mac laptop (or use SSH Windows-native client after installing Bonjour).

  3. find your WLAN adapter device name by

     ifconfig
    

    often it will be named wlan0. Also note the wlan0 IP address for testing if Avahi doesn’t work right away.

  4. edit /etc/avahi/avahi-daemon.conf to have the line

     allow-interfaces=eth0,wlan0
    

    or whatever interfaces you want to use.

Testing Raspberry Pi Avahi mDNS

From a Mac, Linux, or Android device (currently Windows Subsystem for Linux doesn’t work with Avahi mDNS) try

ping raspberrypi.local

If that doesn’t work, try using the IP address as found by typing in the Raspberry Pi

ifconfig

If that doesn’t work, be sure you’ve opened the Raspberry Pi ufw firewall port. You should see Port 22 (or whatever port you have in /etc/ssh/sshd_config on the Raspberry Pi) from

sudo ufw status

If you prefer a GUI, you can use on the Raspberry Pi:

sudo apt install gufw

You can see which interfaces and IPv6/IPv6 Avahi is active on from the Pi

sudo service avahi-daemon status

More Avahi Diagnostics

On Linux

sudo apt install avahi-utils mdns-scan

Then from your laptop (or Pi if diagnosing)

avahi-browse -arp

or

mdns-scan

You should see your device (also try this from your Pi).

Leave a Comment