When you run virtual machines on your local network or under a NAT bridge, checking for changing IP addresses gets tedious. Instead of creating static DHCP leases or manually updating
/etc/hosts on your host, you can assign a clear hostname to the VM and use Avahi to advertise it over multicast DNS (mDNS).
This allows your host machine and any other computer on the same local subnet to reach the VM using
hostname.local automatically.
Set Hostname and Start Avahi
Inside your Linux virtual machine, set your desired hostname and install the
avahi-daemon package:
# Check or set your hostname (e.g., 'ubuntuvm')
sudo hostnamectl set-hostname ubuntuvm
# Install and start Avahi (mDNS publisher)
sudo apt update && sudo apt install -y avahi-daemon
sudo systemctl enable --now avahi-daemon
Verify Connection from Host
From your host terminal (or any machine on the same local subnet), test reaching the virtual machine using its
.local domain:
ping ubuntuvm.local
Troubleshooting resolution issues:
If
ping ubuntuvm.local returns "Name or service not known", verify that the VM network interface is either bridged or on a shared host virtual bridge (such as virbr0). Also verify that UDP port 5353 is not blocked by a local firewall on either machine.