Multicasting multiple mdns names

7,050

Solution 1

A cumbersome solution would be running several instances of the following command in background:

avahi-publish -a -R whatever.local 192.168.123.1

A better solution is probably publishing cnames using python-avahi. See e.g. https://github.com/airtonix/avahi-aliases or http://www.avahi.org/wiki/Examples/PythonPublishAlias

Update:
The avahi wiki seems to be gone. Here is the archived page of the link I've posted: https://web.archive.org/web/20151016190620/http://www.avahi.org:80/wiki/Examples/PythonPublishAlias

Solution 2

First off Avahi doesn't seem to support aliases directly, through one of their standard commands, but their website (essentially offline since sometime in 2016) used to host a very short and simple Python script that would do this.

With this script you can advertise any number of CNAMEs for your current machine like so:

$ ./avahi-alias my-alias.local my-second-alias.local

I did a lot of Googling into all this and you can see my resulting write up here. There's a copy of the original wiki script there and instructions on how to get it running as a service.

The write up also includes my notes on all the various Avahi aliases projects that you can find out there (including the Airtronix project already mentioned here). They all turn out to be just slight variants on the original Python script except for a Ruby based one that's part of the OpenShift Origin server project.

Solution 3

An alternative method, self-contained in a single systemd file, was posted in a bug tracking the lack of this feature.

[Unit]
Description=Publish %I as alias for %H.local via mdns
Requires=avahi-daemon.service
After=avahi-daemon.service

[Service]
Type=simple
ExecStart=/bin/bash -c "/usr/bin/avahi-publish -a -R %I $(avahi-resolve -4 -n %H.local > /dev/null && ip route get 1 | awk '{print $7;exit}')"
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Usage:

# Publish test.local as a pointer to this system:
sudo systemctl enable --now [email protected]
Share:
7,050

Related videos on Youtube

larzz11
Author by

larzz11

Updated on September 18, 2022

Comments

  • larzz11
    larzz11 almost 2 years

    What I would like is to use avahi-daemon to multicast more then one name. So that I could connect to it with domainA.local domainB.local.

    I could then reroute these addresses to a different web interface of different applications with nginx.

    Is it possible to configure the avahi-daemon in such a way that it would multicast multiple names?

    P.S. Using the avahi-daemon is not a requirement. If there is another program that has this functionality I would gladly switch.

    Research and results

    So as suggested by gollum, I tried avahi-aliases first. It is in the repositories, but it did not appear to have installed correctly on my system. According to the instructions is should have installed a script in /etc/init.d/, but there was none.

    I then gave the other link that gollum suggested a try and this worked straight away. It does depend on python-avahi and is just an example of a python script that needs to run in the background. I am now able to broadcast domainA.local, domainB.local and domainC.local and in combination with nginx that leads to different web interfaces on the machine, but are all accessible on port 80.

    Update

    After some more fiddling with the two, I also discovered that avahi-aliases can only broadcast subdomains. So if your computername would be elvispc then avahi-aliases can only broadcast subdomainA.elvispc.local and subdomainB.elvispc.local, where the python script will broadcast any name.

  • gollum
    gollum over 8 years
    And it would be great if you could post your final solution after your research ...
  • larzz11
    larzz11 over 8 years
    It took a bit longer than expected, sorry for that. Will add my results to my post and accept your answer. Thank you for your help!
  • starbeamrainbowlabs
    starbeamrainbowlabs over 4 years
    Dead link to the avahi wiki. The GitHub solution you posted doesn't work on Ubuntu with Python 3 - only Python 2.