Bonjour, Avahi, RPi, Windows… Setup guide

After reading about UPnP vs Zeroconf and how easy to implement the later on, I have decided to tinker with Zeroconf in my home network. Probably the name of the standard Zeroconf does not sound familiar, but its implementation Bonjour (from Applce), and Avahi (from an open source project) are much better known. A quick summary: Zeroconf is built on three technologies:

  • automatic IP address assignment (without a DHCP server),
  • distributed name resolution using mDNS (without a DNS server)
  • network service publishing/discovery using DNS-SD.

The first one is not really relevant nowadays, because everyone has a DHCP server in his home network. But second and third point is still an unresolved problem.

The full guide setting it up on Windows, RPi and Chrome:

1. Install Bonjour on Windows

Getting the latest version of Bonjour from Apple is a bit tricky, because it is not available as a standalone download. First you have to download the 64 bit version of iTunes from http://www.apple.com/itunes/download/. Open iTunes64Setup.exe in Winrar and extract the Bonjour64.msi file. Double click on the extracted Bonjour64.msi file and finish the installation steps.

2. Install Avahi on Raspberry PI (Raspbian)

Log into your RPi with ssh and install libnss-mdns and avahi-utils:

sudo apt-get update
sudo apt-get install libnss-mdns avahi-utils

3. Head scratching

At this point I thought I was done and started to test it with a ping from my Windows notebook. Zeroconf publishes your computer with its hostname on the network under the .local domain. So my RPi should have been available as raspberrypi.local… but it was not working.

ping raspberrypi.local
Ping request could not find host raspberrypi.local. Please check the name and try again.

First I thought that my wifi router running on Openwrt was not forwarding multicast packets used by mDNS between the wireless and wired ports, but the following command on my wifi router printed 0, which means that was not the case:

cat /sys/devices/virtual/net/br-lan/bridge/multicast_snooping

A little snooping on the network with tcpdump from the wifi router quickly revealed the real problem: Bonjour on my notebook was sending out mDNS packets using IPv6 and Avahi was sending out on IPv4.

That meant there were two solutions: a) turn off IPv6 on my notebook b) turn on IPv6 on my RPi. Obviously I choose the later one…

4. Enable IPv6 on RPi

Log into your RPi with ssh and load the ipv6 module

sudo modprobe ipv6

Then add the ip6 module to list of modules loaded during boot. Open /etc/modules in your favorite editor and append ipv6 as the list line in the file. I did it with vi:

sudo vi /etc/modules

Then restart the avahi daemon:

sudo /etc/init.d/avahi-daemon restart
[ ok ] Restarting Avahi mDNS/DNS-SD Daemon: avahi-daemon.

Now the name resolution should work on either IPv6 or IPv4:

C:\>ping raspberrypi.local
Pinging raspberrypi.local [fe80::ba27:ebff:fe0d:5692%14] with 32 bytes of data:
Reply from fe80::ba27:ebff:fe0d:5692%14: time=4ms
Reply from fe80::ba27:ebff:fe0d:5692%14: time=1ms

C:\>ping -4 raspberrypi.local
Pinging raspberrypi.local [192.168.0.24] with 32 bytes of data:
Reply from 192.168.0.24: bytes=32 time=2ms TTL=64
Reply from 192.168.0.24: bytes=32 time=2ms TTL=64

5. Publish services on your network

Publishing services with Avahi is easy. I have got the web interface of FHEM running on port 8083. To publish it I created /etc/avahi/services/fhem.service with following content:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">FHEM on %h</name>
  <service>
    <type>_http._tcp</type>
    <port>8083</port>
  </service>
</service-group>

To publish the ssh and sftp server, I created /etc/avahi/services/ssh.service with the following content:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">SSH on %h</name>
  <service>
    <type>_ssh._tcp</type>
    <port>22</port>
  </service>
  <service>
    <type>_sftp-ssh._tcp</type>
    <port>22</port>
  </service>
</service-group>

The same way you can publish the samba and other services running on your devices. You can find the complete service type list here: http://www.dns-sd.org/ServiceTypes.html

After creating the service definition files, you have to restart the avahi daemon:

sudo /etc/init.d/avahi-daemon restart
[ ok ] Restarting Avahi mDNS/DNS-SD Daemon: avahi-daemon.

You can check the available services on your network with avahi-browser:

avahi-browse -a -t

6. Install DNSSD plugin in Chrome

Windows has no proper gui for Zeroconf, but you can install the DNSSD plugin for Chrome that makes published web sites easily accessible in Chrome. The installation method has changed in the later versions of Chrome for extensions not downloaded the Chrome Web Store: First you have to download the plugin from http://dnssd.me/ by right clicking on „Install for Google Chrome” button. Then open Tools->Extension in Chrome and drag and drop the downloaded crx file into it.

Edit:  The Chrome extension is no longer available as Chrome is abandoning NPAPI. You can let the Chrome developers know you’d like native browser support by clicking the Star on this issue(must be logged-in)

Advertisements

One thought on “Bonjour, Avahi, RPi, Windows… Setup guide

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s