Manual network configuration on local network is a fun thing unless you need to get things working right & quick. By this I mean assigning IP addresses manually, remembering and typing the numbers by hand and so on. You understood.
Often, you want to know what services are available on the local network and how to connect to them. A simple example is a LAN printer or a File Server. All you want is simply to have the device name popup in your Explorer window or any other application-specific program that connects to any of such services.
In this blog entry, without pretending to be complete or even accurate, I will share my experience how to render services visible running on a Linux PC using Avahi [WWW] [WWW]. Similar capabilities in Mac OS X world is seamlessly provided by Bonjour [WWW]. We will focus on Avahi configuration in Arch Linux, keeping in mind that with minor (and may be even simpler steps) the same can be accomplished on any other Linux distribution. Those and similar solutions are implementing what is called Zero configuration networking [WWW]. Why not to roll out a open-source solution featuring local service discovery for all your devices in your home network at home?
With all this preliminary context in place, the need for Avahi services arose when I started to mess with Raspberry Pi [WWW] device. As I am doing all activities on the device using SSH, it become quickly evident that static IP address assigned to the network card manually is not the most elegant solution, especially when moving from network to network (e.g. showing masterpieces off to friends).
I am assuming that network is configured and a SSH daemon is configured and running on the device. What I want is to be able connect the device using hostname without messing with /etc/hosts file on my Mac or any other machine acting as a SSH client.
What you need is to install several packages (run the commands as root or using sudo prefix):
pacman -S avahi nss-msdn
pacman -S dbus pygtk python-dbus python2-dbus
Now you want to enable the Avahi daemon to persist after reboot like this:
systemctl enable avahi-daemon.service
To start it right away, run the commands (yes, DBus must be running before enabling Avahi):
systemctl start dbus.service
systemctl start avahi-daemon.service
If all is OK, you can check the running processes using your favorite top-like utility to see if dbus-daemon and avahi-daemon are running.
Now we need to do a small correction of the /etc/nsswitch.conf to reflect how hostname resolution is taking place. Add or modify existing line starting with “hosts: “:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
Reboot the device to double check if the services are up and running.
When all is done, now comes the tasty part. Check output of following commands (even from another machine with Avahi installed):
- avahi-browse –all
- avahi-resolve -n some_hostname.local
You should see some familiar hostnames that are advertising themselves to the local network and telling what services they are offering. You can see their IP addresses, MAC, service names etc.
Suppose our host has been called “mountain”, it runs a SSH server and has Avahi configured and running. Now you could easily SSH into that box from any other machine on the LAN like this:
This said and coming back to my Raspberry Pi hacking, it suffices to enable DHCP for Ethernet port to be able connect to the device in any other network. Of course, it is assumed that SSH client and the Raspberry Pi are both connected on the same LAN segment…
Credits go to [Arch-WIKI].