Skip to content

Instantly share code, notes, and snippets.

@tomslominski
Last active January 19, 2024 22:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomslominski/9d507acd4036952d65b2364d3750fb36 to your computer and use it in GitHub Desktop.
Save tomslominski/9d507acd4036952d65b2364d3750fb36 to your computer and use it in GitHub Desktop.
Avahi alias systemd service. The first file is the script to be run, which you can store in your home directory. The second file is the systemd unit file which goes in /etc/systemd/system. Make sure on line 6 it references the location of the first file, and that you run systemctl daemon-reload after editing the unit file.
#!/bin/bash
local=$(avahi-resolve -4 -n $(hostname).local | cut -f 2)
hostname=$1
if [ $local != "127.0.0.1" ]
then
echo "Aliasing $local as $hostname."
avahi-publish -a -R $hostname $local
else
echo "Exiting, local address is $local."
exit 1
fi
[Unit]
Description=Publish %I as alias for %H.local via mdns
[Service]
Type=simple
ExecStart=/bin/bash -c "/home/osboxes/avahi-alias.sh %I"
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment