I wanted to be able to SSH into my Raspberry PI without configuring my SSH config with the IP address. Although I have statically assigned it, I think it would be nice to not worry about this detail. All that I really want to be able to do is SSH into the device by its hostname, but we’ll go further and broadcast the SSH service itself.
We may have remembered we had a Raspberry PI after a few months in which case we need to discover where it is in the network:
- Search the local network for devices:
- List the hosts and their IP addresses:
With the IP address we can manually SSH in using some credentials (that we surely stored within a password manager).
Services can be broadcast and discovered on the local network using Avahi which implements a number of different protocols around local networks.
- A link-local IP address for a “direct” connection to the device. This would simply be an address that does not rely on the DHCP service (and is not strictly necessary).
- Hostname resolution via mDNS so that we can SSH into the hostname.
- Descriptive service discovery via DNS-SD (DNS service discovery) as a bonus.
Broadcast SSH on your local network
- Install the service broadcaster
nss-mdnswhich provides host name resolution.
avahi-daemon.service- you may need to restart
/etc/nsswitch.confwhich usually controls the sources from which to obtain name-service information. From Arch: “Insert
- Broadcast the SSH service (you can construct these service files yourself):
cp /usr/share/doc/avahi/ssh.service /etc/avahi/services.
- Observe service works with
avahi-browse -alrtfrom another local machine.
And we are done - we can simply SSH into the displayed domain name/port!
Arch has fantastic documentation around Avahi with further information and examples.