ZeroConf (aka Avahi) network discovery
Using hostnames rather than IP addresses is easier and much more robust. In this guide, we learn how to setup a Linux box for advertising its address by using the Avahi protocol/service.
Motivation
Using IP addresses for accessing other machines is bad practice, for The IP address of a given machine can change unexpectedly — for example, because it has been assigned by a DHCP server from a dynamic pool of available IPs.
Much more preferable is to use hostnames, that map to IP addresses dynamically. On the other hand, This requires a DNS server properly configured and updated.
ZeroConf comes to the rescue: it is an open protocol where all nodes on the same network advertise their services (ports) and host names by broadcasting, and by sharing the same, default local domain: .local.
The name ZeroConf is a bit misleading, for actually there is a configuration step, although it’s minimal and simple. The configuration, additionally, is node local, decentralized, and there is no need for any central server.
How to enable ZeroConf
On MacOS systems, Zeroconf is automatically available, so if your machine name is MyMac, your machine is available on the local network as MyMac.local (case insensitive!).
On Linux, the same protocol and service goes under the name of Avahi. To enable it, do the following steps.
Install the needed packages
sudo apt update && sudo apt install avahi-utils avahi-daemon openssh-serverConfigure the service
Create a file named /etc/avahi/services/ssh.service with the following content:
<!-- See avahi.service(5) for more information about this configuration file -->
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>
</service-group>This is making the host accessible as %h.local, where %h is a wildcard for the current hostname, and also advertising the ssh servoice on TCP port 22.
The list of services advertised on the local network can be obtained with:
avahi-browse -aApply the changes
Remember to enable and start the service:
sudo systemctl enable avahi-daemon
sudo systemctl start avahi-daemonNow you can use <hostname>.local in place of its address: for example, when launching MADS agents, supposing the the broker is running on a device with hostname set to mads-broker, you can simply do:
mads source -s tcp://mads-broker.local:9092 my_plugin.plugin