Avahi mdns aliases


Recommended Posts

Hey guys,

 

Before moving to unraid I had an ubuntu server installation for NAS. The only thing I miss from my old setup is the aliases I had configured for avahi. I still have the script I had build for the aliases which was utilising systemd to start bind to network events.

I would really love to put that back in action.

 

In practice, this is the service I had created for systemd in ubuntu server

[Unit]
Description=Publish %I as alias for %H.local via mdns
Wants=network-online.target
After=network-online.target
BindsTo=sys-subsystem-net-devices-enp5s0.device
Requires=avahi-daemon.service

[Service]
Type=simple
ExecStart=/bin/bash -c "/usr/bin/avahi-publish -a -R %I $(avahi-resolve -4 -n inas.local | cut -f 2)"

[Install]
WantedBy=multi-user.target

 

To use the service it was as simple as creating and starting a parameterised service

systemctl enable inas-avahi@plex.inas.local
systemctl start inas-avahi@plex.inas.local

 

I know unraid is using avahi but I am not familiar with the folder structure and how to make the changes also permanent (some startup scripts that copy files I presume?)

So, where are the files I would need to touch? Also, given unraid is not using systemd, I presume I will need to write an equivalent init.d script or there's some way with unraid?

 

Looking forward to info to get this started. Once ready I will share off course whatever scripts will come out of it so anyone can easily reuse them.

 

Cheers.

Link to comment

First tests - just manually running avahi-publish, reveal I forgot one important component. I need to also proxy the unraid web interface. This means I will need to move it to a different port and put it also behind nginx proxy. Is it feasible to change the unraid web interface port or everything will break?

Link to comment

Almost got it working (was easier than expected).

 

Here's what I have so far - for however might be interested in going down that path

 

Step-1: Change the default ports for the unraid user interface

Go to http://inas.local:8008/Settings/ManagementAccess and change http and https ports. I set them to 8008 and 8443. Just remember to check your ports are not already used by some docker container, etc.

 

Step-2: Install Nginx Proxy Manager (docker from user-apps) - or build your own container. I had my own configs ready from the past server but Nginx proxy manager works just as well and as an added bonus you get a comfortable web-gui with it.

 

Step-3: Configure your subdomains (depends on how you went with step-2)

 

Step-4: Install user-scripts plugin (can put them in /boot/config/go but better skip the pain. Click to create a new script and add the avahi commands in there. For each subdomain add the following command

/usr/bin/avahi-publish -a -R subdomain.domain.tld unraid-ip &

##
## In my case, for my unrain registered with inas.local
## To add jackett.inas.local
## Instead of the IP I used avahi-resolve to actually aquire the IP for the inas.local domain
## This way if the unraid IP changes you do not need to change IPs in the script.

/usr/bin/avahi-publish -a -R jackett.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

 

This is how my final script looks like

#!/bin/bash
#description=Generate avahi aliases
#foregroundOnly=true
#name=Avahi aliases (sub-domains)

echo "sonarr.inas.local"
/usr/bin/avahi-publish -a -R sonarr.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

echo "plex.inas.local"
/usr/bin/avahi-publish -a -R plex.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

echo "proxy.inas.local"
/usr/bin/avahi-publish -a -R proxy.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

echo "sonarr.inas.local"
/usr/bin/avahi-publish -a -R sonarr.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

echo jackett.inas.local
/usr/bin/avahi-publish -a -R jackett.inas.local $(avahi-resolve -4 -n inas.local | cut -f 2) &

 

Next steps (help wanted and appreciated)

 

1. Utilise the args in user-scripts (can we have variable number of variables?) and adjust the script to use them accordingly.

2. Wrap the avahi-publish in a script to monitor for network changes and react accordingly (interface went up, restart avahi-publish, etc).

 

I acknowledge my documentation is insufficient to help people with little knowledge on the subject so feel free to ask and I'll do my best to answer.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.