How to Resolve VirtualBox Host-Only IP by VM Name

centoshost-onlynetworkingvirtualbox

I have a Win 10 physical host with VirtualBox v6.1.34 and a guest OS of CentOS 7.

As a default setting, the VirtualBox Host-Only Ethernet Adapter is on 192.168.56.1/24, and the guest connects to this network adapter in Automatic mode.

After booting up, the guest acquired the address through DHCP, and I verified it by calling the command ifconfig on the guest. To be simple, the hostname of the guest OS is the same as the VM's name.

I also followed this link and verified the record of the DHCP lease. By the way, the leasing record contains the IP and MAC addresses, but I didn't find any indication about either hostname, domain name, or VirtualBox VM name.

However, I could not ping the guest by the VM's name on the physical host. As said before, it is the same as the hostname.

  • I tried ping hostname and ping hostname.local but they didn't work.
  • With the known address, ping 192.168.56.xxx works.

Please let me know if you need more information.

I am new to networking, so I would highly appreciate your suggestions with some pointers on the basic concepts, e.g. subnet, gateway, router, DNS, DHCP, etc.

Best Answer

Name lookup based on DHCP leases is done via local DNS that needs to be provided by the DHCP server in question (i.e. by VirtualBox's internal "host-only" DHCP service). Synchronization of DHCP leases to DNS entries isn't inherently built-in to DHCP but is a feature that needs to be separately implemented by the software's authors, and as far as I can see in VirtualBox's Dhcpd source code, such integration isn't implemented at all.

(In addition, the client (i.e. your host OS) also needs to be configured to actually use that DNS server. This is also unlikely to be the case, as VirtualBox's DNS is meant for VMs so it forwards the requests to wherever the host OS configuration tells it to... so if the host tries to use VirtualBox's DNS, you're going to get a DNS request loop and won't be able to resolve anything at all.)

Direct (non-DNS) name lookup is usually based on the mDNS or LLMNR protocols. For bare host or host.local names to work, the VM needs to actually serve at least one of those protocols – usually via avahi-daemon for mDNS, via systemd-networkd for LLMNR (or both). Install one of those services and make sure the VM's firewall allows the inbound UDP query packets.

Related Question