I need to create a network consisting of four virtual machines (OS: Ubuntu Server 22.10), two of which are web servers, following the requirements:
- 1. All VMs must be able to communicate with each other.
- 2. All VMs must have Internet access.
- 3. The host machine must be able to communicate with each VM using its FQDN. For example, the user must be able to access a site on a virtual web server through a web browser of the host OS, or create an SSH connection between the HM and any VM.
Problem
The requirements stated above are easy to meet. Two network adapters may be connected to each VM:
- 1. Attached to: NAT (for Internet access)
- 2. Attached to: Host-only Adapter / Host-only Network (for Host → VM and VM ↔ VM communication possibilities)
The third requirement can be met in the following way: set a different static IP address for each Host-only Adapter. Then, make an entry for each IP address and the assigned canonical hostname in the hosts file of a host OS.
But... For macOS, which I use, the Host-only Adapter option is marked as deprecated. This type of adapter is replaced by the Host-only Network adapter.
The Host-only Network adapter does not provide the ability to set a static IP address. Instead, it provides the ability to set a DHCP range.
In that case, when using the Host-only Network adapter, the lowest available IP address from the range will be assigned to each VM upon connection [Oracle VM VirtualBox User Manual, Section 6.7, "Host-Only Networking"].
It is a problem if there are several VMs in a network, I guess. The user may start VMs in a different order each time, which in turn may lead to a regular change of IP addresses of the VMs. Therefore, the entries in the hosts file become outdated.
Question
What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs in that case?
The first thing that comes to mind is to make sure that each VM requests a specific IP address from the DHCP server (or, more likely, configure the DHCP server to assign a fixed IP address for each VM). To be honest, I do not know how to do it properly.
The second thing — use mDNS. It does not seem like an elegant solution. Also, I think that mDNS makes sense only when it comes accessing a virtual server from any device in a local network.
I would be very grateful for any hints!
Additional Information
I tried to use VBoxManage dhcpserver, but it seems like it does not work for Host-only Networks (VBoxManage hostonlynet):
- 1. VBoxManage list dhcpservers — my list is empty, but the previously created Host-only Network works correctly.
- 2. I added a new DHCP server for the Host-only Network using VBoxManage dhcpserver add and reserved a fixed IP address for one of the VMs using the --fixed-address parameter, but the VM continued to receive an address different from the reserved one.