Configure Zeroconf to broadcast multiple names
Solution 1:
Here's a little systemd service that lets you specify an alias for your current machine like test.local
in addition to hostname.local
(assuming your machine is called hostname
).
Setup
First install avahi-utils, if you haven't already:
sudo apt-get install avahi-utils
Then put the following into /etc/systemd/system/[email protected]
[Unit]
Description=Publish %I as alias for %H.local via mdns
[Service]
Type=simple
ExecStart=/bin/bash -c "/usr/bin/avahi-publish -a -R %I $(avahi-resolve -4 -n %H.local | cut -f 2)"
[Install]
WantedBy=multi-user.target
(The avahi-resolve
is used to get the current IP address that is already being published for the hostname)
Use
Then to make the current machine available as test.local
in addition to its current hostname.local
, you would enable the service with:
sudo systemctl enable --now [email protected]
You can enable multiple aliases by starting multiple services, e.g.
[email protected]
and [email protected]
, which makes use of systemd's multi-instance features:
sudo systemctl enable --now [email protected]
sudo systemctl enable --now [email protected]
Naturally you can disable each alias independently, too, with:
sudo systemctl disable --now [email protected]
Enjoy!
Solution 2:
You can configure Avahi to publish arbitrary hostnames using /etc/avahi/hosts
, but you need to specify the exact IP address to map the hostname to. There doesn't seem to be a way to publish multiple hostnames to the IP addresses detected by Avahi. You could write a startup script which populates /etc/avahi/hosts
after discovering the VM's IP address.
Solution 3:
I've used a small project named avahi-aliases
before, its not in the debian repository, and seems to be a little less than maintained. Also on github here https://github.com/airtonix/avahi-aliases
Solution 4:
Why not just set up your ubuntu server to be a dns and dhcp server and not worry about zeroconf? First, configure the dhcp server to give out addresses in some range sufficient for your needs. Then, set up a forwarding nameserver on the machine. These instructions are pretty similar to what you want to do. Basically you are allowing the dhcp server to change your dns server on the fly. Then when the other virtual machines on the network come up, they send their preconfigured names to the dhcp server. The dhcp server in turn sets those names in dns for your local domain.
Another very simple option is to set up something like DNSmasq. DNSmasq can read the server's /etc/hosts file and serve those entries up via dns to other machines on your network. So in this scenario you would maintain a big hosts file on the server of all the VM names, and the machine would again automatically serve those names over dns. You would still want to use dhcp in this case so the VMs could get addresses on your network automatically, but this is a simpler approach than configuring BIND for dns.
My suspicion is that dhcp + dnsmasq will probably work for you, unless you are attempting to run massive numbers of VMs.