Saturday, August 16, 2014

Setup Avahi to Use mDNS with a Raspberry Pi Running Arch Linux

Avahi is a simple open source Zero Configuration networking solution for Linux. It is tantamount to Bonjour for the OSX platform. The setup is pretty simple and straight forward. Since we have connected our Pi's to our laptops with a static IP it is really not necessary to use Avahi for name resolution because we could just add a line to our /etc/hosts file. However, if we have printers and other network clients that we would like to make available to our Pi and Laptop Avahi is a good choice to use to access these other DHCP clients on our network and the setup is simple enough.

Step 1:

Make sure you have a hostname set in the /etc/hostname on your Pi:

nano /etc/hostname
# /etc/hostname 
my-pi 

Make sure a hostname is set on your laptop also. If using systemd:

nano /etc/hostname 
# /etc/hostname 
my-laptop 

or if your laptop uses systemv: 

nano /etc/conf.d/hostname 
# Set to the hostname of this machine 
hostname="my-laptop" 

Step 2:


Install Avahi on your Pi:

pacman -Sy avahi nss-mdns 

Install on your laptop per your distro's package manager.

On both the Pi and the laptop, setup mDNS in your nsswitch.conf file. This will tell your OS to do a lookup with Avahi along with other name resolution methods:

nano /etc/nsswitch.conf 

find the hosts line and edit it as such:

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

Step 3:

Start the daemon on your Pi:

systemctl enable avahi-daemon
systemctl start avahi-daemon.service 

Start the daemon on your laptop the same way if you use systemd.
If you use rc-update do:

rc-update add avahi-daemon default

and start the daemon:

/etc/init.d/avahi-daemon start 

Step 4:

See if it all works as expected.
Try:

avahi-browse --all 

on each box to see what is shown on your network. You will need Zero Config software on every client in your network you would like to interact by name.local.
Now try to ping from your laptop:

ping my-pi.local

and from the Pi:

ping my-laptop.local

To see if your ping is working.

Step 5


If all works as expected, reboot and retest with Step 4.

Troubleshooting


If you still have an old IP assigned to the name for some reason (e.g. and earlier yet removed entry in /etc/hosts) try:

avahi-resolve -n my-pi.local 

to fix.

Note:

avahi-discover Cannot be used without X, so you are out of luck if you run your Pi Headless, but you can still use it from your laptop and such.

No comments:

Post a Comment