FYI: Bonjour / Zeroconf on Raspbian


12 posts
by Sander » Sun Sep 23, 2012 3:21 pm
A FYI:

With Bonjour / Zeroconf activated on your Raspbian, it's easy to reach your Raspberry Pi from other devices on your LAN: just use hostname "raspberrypi.local" in your ssh / ping / browser, and it should work. That is, if the other device has Bonjour / Zeroconf installed too. That's true for OSX and Ubuntu. On Windows, it works if you have itunes installed, or "Bonjour Print Services for Windows".

On Raspbian, type this:
Code: Select all
sudo apt-get update
sudo apt-get install libnss-mdns

The last command will also install avahi-daemon.

And that's it. From my Ubuntu, I can now reach my Raspi easily:

Code: Select all
sander@R540:~$ ping -c 4 raspberrypi.local
PING raspberrypi.local (192.168.1.54) 56(84) bytes of data.
64 bytes from raspberrypi.home (192.168.1.54): icmp_req=1 ttl=64 time=96.6 ms
64 bytes from raspberrypi.home (192.168.1.54): icmp_req=2 ttl=64 time=3.56 ms
64 bytes from raspberrypi.home (192.168.1.54): icmp_req=3 ttl=64 time=2.71 ms
64 bytes from raspberrypi.home (192.168.1.54): icmp_req=4 ttl=64 time=2.65 ms

--- raspberrypi.local ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 2.652/26.385/96.604/40.542 ms
sander@R540:~$

sander@R540:~$ ssh -X pi@raspberrypi.local.
pi@raspberrypi.local.'s password:
Linux raspberrypi 3.2.27+ #160 PREEMPT Mon Sep 17 23:18:42 BST 2012 armv6l
...


On Ubuntu, you can use "avahi-discover" to see all Bonjour services on your LAN.

HTH
User avatar
Posts: 174
Joined: Wed Aug 31, 2011 1:01 pm
by inder » Wed Sep 26, 2012 5:35 pm
Just curious; what happens when there are two Rpis in the same network? Does Avahi assign the second one another default name?
Posts: 23
Joined: Wed Aug 22, 2012 7:44 pm
by titusmagnus » Thu Nov 22, 2012 2:07 pm
If there are name collisions on the same network, the newer device will automatically append a number that uniquely identifies itself. For example, if a device called "GameServer" already exists, the new one called "GameServer" that joins the network will detect the collision and rename it to "GameServer #2" or perhaps "GameServer (2)".
Posts: 1
Joined: Thu Nov 22, 2012 2:01 pm
by raspberrycraig » Fri May 10, 2013 1:45 am
Ah, so in this case, the second Raspberry Pi would be "raspberrypi.local #2" or something similar?
Posts: 1
Joined: Fri May 10, 2013 1:42 am
by tweakdeveloper » Mon Sep 02, 2013 10:09 pm
If this becomes a problem, just give one of them a different hostname (substituting "desired-hostname" for your own, of course ;) ):
Code: Select all
hostname desired-hostname

For example, if I wanted to name my Pi GLaDOS, the command would look like this:
Code: Select all
hostname glados
Posts: 1
Joined: Mon Sep 02, 2013 10:02 pm
by geekuskhan » Wed Jan 01, 2014 12:16 am
This works great. On my ubuntu laptop and my gf's iphone everything is perfect. Any ideas how to get this to work with my android phone? Oh I should mention that i am running a little webserver on the pi so I would like to be able to just type in raspberry.local into the browser.
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by Joe Schmoe » Wed Jan 01, 2014 12:23 am
As usual:

Keep in mind that avahi-daemon is a nifty thing - when it works.

It works about 1/3 of the time. Again, as I say, it's really neat when it is working.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm
by hgreen » Sun Mar 01, 2015 2:18 pm
Realise this is a little late, but I just wrote a blog post about connecting to the Raspberry Pi from an Android Application using its Zeroconf/Bonjour hostname. It turns out there are two ways to do it, and you have to specifically use either the NSD (Network Service Discovery) library or the jmDNS Java library from your application. As far as I know browser apps in the Play Store don't have the capability. There is an app called Bonjour Browser that will let you test the functionality.

Here's my blog post:

http://www.dodgycoder.net/2015/02/setting-up-bonjourzeroconfmdnsnsd.html
Posts: 10
Joined: Tue Sep 04, 2012 1:32 am
Location: Perth, Australia
by sim667 » Fri Jun 05, 2015 6:57 pm
I've been using this and its been working well on my internal network. However I'm trying to get it to reflect bonjour names across a pptp VPN (pptpd).

Does anyone know if this is possible, basically I'd like the devices still to appear in the finder sidebar, when I'm connected to vpn from work or somewhere like that.
Posts: 8
Joined: Tue May 19, 2015 9:00 am
by a.corkran » Sat Sep 26, 2015 5:04 am
tried to use the method described to change hostname. it created an error.
Code: Select all
pi@raspberrypi ~ $ sudo hostname
raspberrypi
pi@raspberrypi ~ $ sudo hostname bearpi
pi@raspberrypi ~ $ sudo hostname
sudo: unable to resolve host bearpi
bearpi
pi@raspberrypi ~ $ hostname
bearpi
pi@raspberrypi ~ $ sudo hostname
sudo: unable to resolve host bearpi
bearpi
pi@raspberrypi ~ $ hostname
bearpi
pi@raspberrypi ~ $ hostname bearpi
hostname: you must be root to change the host name



as shown it failed to correctly update.
http://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/ shows the correct procedure. paraphrased below.

Two things to check (assuming your machine is called raspberrypi, you can change this as appropriate):
Code: Select all
pi@raspberrypi ~ $ sudo nano /etc/hostname

1. check that the /etc/hostname file contains just the name of the pi: "raspberrypi"
2. change to name of choice

3. then
Code: Select all
pi@raspberrypi ~ $ sudo nano /etc/hosts


/etc/hosts has an entry for localhost. It should have something like:
Code: Select all
127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       raspberrypi

4. change last line to same as step 2.

finally commit the changes
Code: Select all
sudo /etc/init.d/hostname.sh

then reboot
Posts: 16
Joined: Thu Jun 11, 2015 3:06 am
by tmetro » Tue Jul 05, 2016 3:41 pm
At some point since this thread was created Raspbian added support for ZeroConf. Sometime on or prior to Release 2016-05-27 (which is the first release I tried) it was found that avahi-daemon (an alternate ZeroConf daemon) was installed and running, and it was confirmed the Pi was publishing a 'raspberrypi' host name.

(The discussion above on changing the host name is still relevant.)
Posts: 1
Joined: Tue Jul 05, 2016 3:35 pm
by DirkS » Wed Jul 06, 2016 8:11 am
tmetro wrote:At some point since this thread was created Raspbian added support for ZeroConf.

Avahi was added in the 2015-05-05 image (see http://downloads.raspberrypi.org/raspbi ... _notes.txt)
Posts: 6950
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK