Archive

Posts Tagged ‘Linux Tricks’

Avahi – Zero Configuration Networking for linux.

January 31st, 2009 nawaman 1 comment

Introduction

Computer networking is a complex stuff. There are a lot of things involve, just like other engineering problems, trying to make use of the less to do the most. In this case, they try to send a lot of information on only a few wires in a network cable. There are so many hardware things and software things involve like routers, switches, addressing, protocol and many more. Big groups of people get hired specifically to get this thing up and continue running. The consequence of all these is the wonderfully efficient network (including the Internet) we all enjoy and very suffering (and sometime – continuous) headaches to those non-geek or less-experienced-geek (me included) who happen to have to set those up.

And here comes – Avahi. Avahi is an implementation of a technological standards called ZeroConf or Zero Configuration Networking. Before you are getting too much exciting, Avahi is not a silver bullet for dummy as you may expect from reading what I wrote above. Its promise is to make it very easy for application to publish services and discover those services on the current network without getting your hands so dirty. Basically, you still need to have your network up and running before using Avahi but after that applications can be easily be written to take what Avahi have to offer without the need to know about the status of the network it is running on.

To see how easier your life (as a regular user) can be with Avahi, try install and run a program called Giver (for Ubuntu users – click here). Be sure to run it on at least two machines in the same network. Giver will list names and information about users in the same network who is currently running giver. You can click on that user and send send a file or folder. You can drag a set of files on to that user icon to start sending files. As you see, there is no need to tell Giver anything about your network setup or even you user information. Giver with the helps of Avahi will discover all those. Users just simply run it.

I am so impress how easy life can be with Giver so I looked into its source and found that it is simply creating a port listener and register the service to Avahi. However, since giver is implemented in C#, I am not interested in getting involve with it (I see Microsoft’s shadow behind it). I sincerely afraid that one day Microsoft will pull the pin and all open-source projects written in C# or on Mono in general will be left out hanging in the air for a few milliseconds before freely fall to sudden a death. So, I may someday reimplementing Giver in Java but that for later.

How to do it

With a very long introduction, in this article, I will show you how can you use Avahi to publish your service and use Avahi to recover the services. Are you ready? Here we go…

To publish:

nohup avahi-publish -s "<service name>" _<protocol name>._tcp <port> <Txt ...> 2>&1 > /dev/null &
nohup and & at the end is simply to tell Linux terminal that this will be run in the background.
-s means service.

<service name> is human friendly name of the service you are providing (ensure to have the server name in it)

<protocol name> is the name of the protocol (set of rules govern how or what data the application is going to be used.)

<port> is the part number of the service.
<Txt …> is a set of text for more information (like setting)
2>&1 > /dev/null is to tell nohup that no log should be created

e.g.

  nohup avahi-publish -s "Test service on NawaHP" _nawaman._tcp 42655 "User=NawaMan" "Location=Home" 2>&1 > /dev/null &

To discover:

avahi-browse -a -t -r
-a is simply to tell linux terminal that this will be run in the background.
-t means service.

-r is human friendly name of the service you are providing (ensure to have the server name in it)

The result should be something like this:

= wlan0 IPv4 Test service on NawaHP                       _nawaman._tcp          local
   hostname = [ComputerName.DomainName]
   address = [192.168.0.103]
   port = [42655]
   txt = ["User=NawaMan" "Location=Home"]

As you see, information such as host name, IP address, port number and protocol name is clearly available and that is more than enough to get the communication started.

Simple? Very (for a greek :D ).