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/avahi-alias@.service
[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 avahi-alias@test.local.service
You can enable multiple aliases by starting multiple services, e.g.
avahi-alias@test1.local.service
and avahi-alias@test2.local.service
, which makes use of systemd's multi-instance features:
sudo systemctl enable --now avahi-alias@test1.local.service
sudo systemctl enable --now avahi-alias@test2.local.service
Naturally you can disable each alias independently, too, with:
sudo systemctl disable --now avahi-alias@test2.local.service
Enjoy!