John Siu Blog

Tech - Business Tool, Personal Toys

Avahi and Multiple Alias

☰ Table of Content

Configure Avahi to broadcast multiple names.

Ref:

Configuration Files

Create the two files below.

/etc/systemd/system/avahi-alias@.service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Publish %I as alias for %H via mdns

[Service]
Type=simple
ExecStart=/bin/bash -c "/etc/systemd/system/avahi-alias.sh %I"
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

/etc/systemd/system/avahi-alias.sh:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/usr/bin/bash

mdns_domain="local"
IP=$(avahi-resolve -4 -n $(hostname -s).$(mdns_domain) | cut -f2)
ALIAS=$1

if [ $IP != "127.0.0.1" ]
then
	echo "Aliasing $IP as $ALIAS."
	avahi-publish -a -R $ALIAS $IP
else
	echo "Exiting, local address is $IP."
	exit 1
fi

Enable Alias

1
systemctl enable --now avahi-alias@<alias>.local.service

John Siu

Update: 2025-07-29
Tag
comments powered by Disqus