When working with virtual machine configurations that need to be portable across networks, traditional DNS solutions often create dependencies we can't afford. Zeroconf (specifically Avahi in Linux environments) provides a solution, but its default behavior only advertises a single hostname.
Here's how to make Avahi broadcast multiple names for your Ubuntu Server instance. First, edit the Avahi configuration:
sudo nano /etc/avahi/avahi-daemon.conf
Add or modify these parameters:
[server]
host-name=primary-hostname
domain-name=local
use-ipv4=yes
use-ipv6=yes
publish-addresses=yes
publish-hinfo=yes
publish-workstation=yes
[publish]
publish-addresses=yes
publish-a=yes
publish-ptr=yes
publish-domain=yes
For each additional hostname, create a service file:
sudo nano /etc/avahi/services/extra1.service
With this content (duplicate for each hostname):
<service-group>
<name replace-wildcards="yes">extra1-hostname</name>
<service>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>
If Zeroconf proves insufficient, you can configure VirtualBox's built-in DNS server:
VBoxManage modifyvm "VM_NAME" --natdnshostresolver1 on
VBoxManage setextradata "VM_NAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/hostname1/Settings" "hostname1.local"
VBoxManage setextradata "VM_NAME" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/hostname1/IP" "192.168.1.100"
After restarting Avahi (sudo systemctl restart avahi-daemon
), verify with:
avahi-browse -a -r
dig @224.0.0.251 -p 5353 extra1-hostname.local
Remember that all names must end with .local
for Zeroconf resolution to work properly across all platforms.
When working with virtual machine configurations that need to be portable across networks without DNS infrastructure, Zeroconf (implemented via Avahi on Linux) becomes crucial. The standard Avahi configuration only broadcasts a single hostname, but many virtualization scenarios require multiple service announcements.
The solution involves creating multiple Avahi service files, each announcing a different hostname alias. Here's how to implement this on Ubuntu Server:
# Install necessary packages
sudo apt-get install avahi-daemon libnss-mdns
# Create the primary configuration
sudo nano /etc/avahi/avahi-daemon.conf
Add these critical parameters:
[server]
host-name=primary-host
domain-name=local
enable-dbus=no
publish-addresses=yes
publish-hinfo=no
publish-workstation=no
[wide-area]
enable-wide-area=no
Create additional service files in /etc/avahi/services/ for each alias:
# Example: /etc/avahi/services/alias1.service
<service-group>
<name replace-wildcards="yes">Alias1</name>
<service>
<type>_http._tcp</type>
<port>80</port>
</service>
</service-group>
# Example: /etc/avahi/services/alias2.service
<service-group>
<name replace-wildcards="yes">Alias2</name>
<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>
</service-group>
For VirtualBox environments, you can configure NAT DNS:
VBoxManage modifyvm "VM Name" --natdnsproxy1 on
VBoxManage modifyvm "VM Name" --natdnshostresolver1 on
Verify your setup with these commands:
avahi-browse -a # List all services
avahi-resolve -n primary-host.local # Test resolution
sudo systemctl restart avahi-daemon # Apply changes
Common issues to watch for:
- Firewall blocking mDNS (UDP 5353)
- Multiple network interfaces causing conflicts
- Duplicate hostname conflicts on the local network