Here's a little systemd service that lets you specify an alias for your current machine like test.local
in addition to hostname.local
(assuming your machine is called hostname
).
Setup
First install avahi-utils, if you haven't already:
sudo apt-get install avahi-utils
Then put the following into /etc/systemd/system/[email protected]
[Unit]
Description=Publish %I as alias for %H.local via mdns
[Service]
Type=simple
ExecStart=/bin/bash -c "/usr/bin/avahi-publish -a -R %I $(avahi-resolve -4 -n %H.local | cut -f 2)"
[Install]
WantedBy=multi-user.target
(The avahi-resolve
is used to get the current IP address that is already being published for the hostname)
Use
Then to make the current machine available as test.local
in addition to its current hostname.local
, you would enable the service with:
sudo systemctl enable --now [email protected]
You can enable multiple aliases by starting multiple services, e.g.
[email protected]
and [email protected]
, which makes use of systemd's multi-instance features:
sudo systemctl enable --now [email protected]
sudo systemctl enable --now [email protected]
Naturally you can disable each alias independently, too, with:
sudo systemctl disable --now [email protected]
Enjoy!