13

I want to broadcast multiple host names on a local network only from a single instance of Ubuntu Server 10 with Zeroconf or something similar. It has to be zeroconf or similar because it's going to be used in a virtual machine configuration and will be copied around so I can't depend on an external DNS server. I've collected a number of resources, but haven't been able to figure it out. Is there a way to do this?

Here are some resources I've gathered: http://bit.ly/l5W4ab

EDIT: It would also be fine to set up VirtualBox to be a DNS server too.

1

4 Answers 4

5

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.

2
  • I ended up solving this problem an entirely different way, but I am tempted to come back to this problem and try this solution. It sounds promising. Apr 20, 2012 at 14:34
  • 2
    This doesn't work for pointing an alias to the same server running avahi. I had to use @nonrectangular's answer to make it work. I gather the -R argument is the key difference between it not working from the hosts file but working using avahi-publish.
    – KrisG
    May 11, 2020 at 12:50
21

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!

4
  • Is it possible to control the full aliased domain? I have old NAS devices that only accept .com domains for SMTP alerts. They don't support SSL/TLS, so I need to point them to an internal mail relay to hand off to GMail. I want to use this to set up the relay as something like smtp.local.com that the NAS will accept.
    – McGuireV10
    Jul 14, 2020 at 12:50
  • 1
    For some reason avahi-publish was getting the wrong IP address when started on boot on Ubuntu 20.10. I tried delaying the service starting until after avahi-daemon and network ability, but neither helped, so I wrote a script to simply wait until the correct IP address is available. It is available here gist.github.com/tomslominski/9d507acd4036952d65b2364d3750fb36, with some instructions. The actual service still works in the same way, so you can use this to alias multiple domains. Hope this helps somebody! Dec 29, 2020 at 17:54
  • This is an awesome answer, just came here to say that!
    – Xt432ba5
    Feb 13, 2023 at 22:42
  • I noticed my aliases failing on startup because avahi-daemon.service hadn't yet advertised $hostname$.local. So I added After=avahi-daemon.service to the [Unit] and Restart=always to the [Service] definitions. Jan 4 at 1:50
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

2

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.

1
  • The ubuntu server itself is the virtual machine. It needs to broadcast its own names without the help of an external DNS server. I need this to work for my coworkers in coffee shops, etc. Put the vm into host-only or shared (nat) mode and the vm should broadcast names itself. I just had another thought... if I could make virtual box (or vmware) be the local DNS server, that should work. May 11, 2011 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .