Using Zeroconf on Linux: What Is It Good For?
By Juliet Kemp
avahi is installed by default on Debian and Ubuntu systems, but few people seem to use it to any extent. It’s supposed to be a service auto-discovery, but what services exactly is it set up to discover? I decided to take a look and figure out if I could actually make it do something I wanted.
avahi runs mDNS plus DNS-SD: that is, multicast DNS plus DNS service discovery. Multicast DNS means that each equipped host stores its own DNS records. A multicast address (220.127.116.11) is used by clients wishing to get the IP address of a given hostname, and that host responds to the client request with its IP address. DNS-SD uses the same technology, but in addition to regular DNS information, hosts also publish service instance information: they announce what services they provide and how to contact those services. All of this is intended to mean that hosts and services can connect to one another without requiring any user configuration: known as Zeroconf sharing. Great for those who aren’t comfortable doing manual setup — or who are just lazy!
In truth, as yet there isn’t that much Linux software that really uses mDNS. Apple have made rather more use of it: their software is called Bonjour, and handles printer setup, music sharing via iTunes, photo sharing via iPhoto, Skype, iChat, and an array of other software services. However, in terms of the technical implementation, avahi is an excellent piece of software, and capable of doing everything that Bonjour does. It’s been suggested that the Debian/Ubuntu dev teams are actually trying to help give mDNS a bit of encouragement with the inclusion of avahi.
So, what can you do with avahi on your Linux box? One possibility is to use it for networked music sharing. In particular, if some of your music is on laptops that appear and disappear from the network as they are moved around and shut down or booted up, auto music discovery is very handy. This is the same tech that Apple uses for iTunes. Since I have a Mac laptop and a couple of Debian desktops which live in another room, this sounded promising.
Unfortunately, it currently only works in one direction: rhythmbox can connect to an iTunes share but can’t actually get at any of the music (this is due to a change in protocol from iTunes 7.0). This is enormously irritating and entirely Apple’s fault. Sharing in the other direction works fine: use the “Plugins” menu to configure sharing via DAAP (remember to hit the “configure” button and then check the “share my music” box), and your share will be made available. It’ll show up automatically in iTunes on a Mac; in rhythmbox you’ll need to use the “Connect to DAAP share” option in the Music menu of rhythmbox, and give the hostname/IP address and port (3689) to connect to. If you add music it won’t appear in the share until you either restart rhythmbox (client-side), or disconnect and reconnect the share in iTunes. (Note: if running a firewall, you’ll need to open appropriate holes in it for outbound sharing, although not for inbound.)
You can also set up your machine to appear on your local network as machinename.local (can be useful for a home network if you haven’t got proper local DNS running; I certainly don’t and usually rely on setting options in ~/.ssh/config so I don’t have to remember IP addresses). Copy the sample service file in /usr/share/doc/avahi-daemon/examples/ssh.service to /etc/avahi/services/ and restart the avahi daemon. Then run avahi-browse-domains -a -t (from the avahi-utils package), and you’ll see your machine listed as running an SSH service. To browse all available services, use avahi-browse -a -r -t (-a shows all services, -r resolves the details of the services, and -t terminates once it has a full list).
Similarly, whilst CUPS handles printer setup, avahi should in theory at least make it easier to set a printer up as remote (by setting the printer up in avahi on the machine to which it’s connected). Currently, however, this seems to be problematic: you’ll need to write your own ipp.service file and add it to the /etc/avahi/services/ directory. The avahi.services (5) man page is comprehensive, but unfortunately there’s no example file in the package for printers (just for ssh, as above). I wasn’t able to test this directly, being a dead-tree-free operation! It may be more useful if you’re running Macs on your network: Bonjour should autodetect the printer once it is shared. There are also other possibilities: remote desktop sharing, for example, and document sharing.
It’s irritating that more of this isn’t more straightforward. I really like the ease of setting up machinename.local hostnames, but it’s a nuisance that music shares don’t autodetect. (And more of a nuisance that it doesn’t work with iTunes, but that’s not the fault of avahi.). Similarly, it seems that printer autodetection really isn’t quite there yet either. When compared with Apple’s implementation of this, the infrastructure does seem to be present, but the user interface just isn’t yet. (If there are software options that I’m missing, please let me know!)
So, yes, there are uses for avahi, but it seems like it’s still — in terms of the user experience, anyway — a project which needs more work. I can understand if it is the case that Debian/Ubuntu are making it a default install in order to encourage more user software. I’d certainly like to see more use made of this. It has the scope to be much more useful (especially for those who are lazy, or running Mac/Linux networks) than it is now; hopefully that will develop further in the near future.
Article courtesy of Linux Planet