Sometimes you might find it hard to keep track of the IP address of your devices in your local network. Imagine having three Raspberry pi’s and keeping track of their IP when you want to SSH into them in a local network.
Most Debian OS’s if not all come installed with the Avahi mDNS. The Avahi mDNS serves as a local DNS and it makes use of the
.local extension which is used as a specially used domain and reserved for personal use and local networks.
So instead of sshing into your Raspberrypi by doing
ssh email@example.com you can ssh into your Raspberrypi using its hostname with the .local extension e.g
To view the hostname of your Raspberrypi, run this command:
And to change the hostname of your Raspberrypi, run this command:
hostnamectl set-hostname [custom-name]
So in a scenario where you have three Raspberrypis, you can run these commands:
# Run this in your first Raspberrypi hostnamectl set-hostname mypi-1
# Run this in your second Raspberrypi hostnamectl set-hostname mypi-2
# Run this in your third Raspberrypi hostnamectl set-hostname mypi-3
After running these commands you would need to reboot your router so that it can have the updated list of hostnames 😁
To ssh into your first Raspberrypi, you can simply run
This is easier than using its IP address.
Another good thing about the Avahi mDNS is that it binds your device’s IP address to its local domain so even when the IP address of your device changes, you don’t need to worry about that because sshing using your device’s hostname with the
.local extension would still work.
Also, note that this setup isn’t only restricted to Raspberrypi, you can as well change the hostname of your Debian computer using the same commands above 😜
Thanks and I hope you enjoyed learning a little bit about the Avahi mDNS.😅