Last active
September 3, 2024 12:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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
Thank you very much for your solution!! It works perfectly!!
For others using this on Ubuntu 22+, the bash is located at /usr/bin/bash.