What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
alexstreltsov
Posts: 3
Joined: 14. Jan 2023, 15:53

What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Post by alexstreltsov »

Goal

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. 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. 1. Attached to: NAT (for Internet access)
  • 2. Attached to: Host-only Adapter / Host-only Network (for Host → VM and VM ↔ VM communication possibilities)
Alternative, a single Bridged Adapter may be used instead of the two adapters mentioned above, if it is acceptable for the VMs to be in the same network as the HM.

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. 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.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Post by scottgus1 »

The most elegant way is Bridged, so each VM takes its own place on the home/office LAN. Then the host and any other LAN device can access the VMs directly. And if there is an OS name publishing service running, the names of the VM OS's can be used instead of IP addresses. (Only issue with Bridged is that you may have to use wired Ethernet; Mac's Wifi hasn't allowed Bridged to work since Monterey at least.)

Mac Ventura forced the devs to come up with another way to do Host-Only. This other way may still be under development or may still have bugs.

If you are not yet up to Ventura, you can still use Virtualbox 6.1, which has the old Host-Only setup. Then you can use Host-Only & NAT with static IPs in the VMs, and swish, nothing but net.

A thought: Isn't DNS is supposed to handle hosts whose IP addresses may change? I don't know much about that part of networking, but I do know that dynamic-IP Windows PCs on my home LAN can be accessed by \\PCname, not only \\ip.add.re.ss. If you could set up such an arrangement in your network, your VMs might be able to still use the names and have dynamic IPs. I wouldn't know how to do that, though.

A Host-Only network is essentially an unmanaged switch with the host on one port, optionally a DHCP server device on another port, and the VMs on the rest of the ports. If you can take a group of physical PCs networked together through an unmanaged switch using dynamic IPs, and get them to talk to each other by their FQDN's, then you should be able to apply the same solution to the Host-Only network.
alexstreltsov
Posts: 3
Joined: 14. Jan 2023, 15:53

Re: What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Post by alexstreltsov »

Thank you for your reply, scottgus1!
scottgus1 wrote:The most elegant way is Bridged, so each VM takes its own place on the home/office LAN. Then the host and any other LAN device can access the VMs directly. And if there is an OS name publishing service running, the names of the VM OS's can be used instead of IP addresses. (Only issue with Bridged is that you may have to use wired Ethernet; Mac's Wifi hasn't allowed Bridged to work since Monterey at least.)
Yes, I mentioned the Bridged option in my original post, but:
  • Wired connection in our "wireless" world... It doesn't seem like an elegant solution.
  • I think that if there is no need to access the virtual machine from any device on the physical network, then using Bridged is not justified enough. Just as an example.
scottgus1 wrote:A thought: Isn't DNS is supposed to handle hosts whose IP addresses may change? I don't know much about that part of networking, but I do know that dynamic-IP Windows PCs on my home LAN can be accessed by \\PCname, not only \\ip.add.re.ss. If you could set up such an arrangement in your network, your VMs might be able to still use the names and have dynamic IPs. I wouldn't know how to do that, though.
I don't know much about networking at all, but, as I understand, this is what mDNS is used for, however, I guess that it works correctly (with no extra headache) only with the Bridged Adapter. I am going to try Avahi to solve the issue.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Post by scottgus1 »

alexstreltsov wrote:I guess that it works correctly (with no extra headache) only with the Bridged Adapter.
Bridged is also a group of "PCs" attached to an unmanaged switch, just like a Host-Only network, or a group of real PCs. Whatever works on Bridged should also work on Host-Only.
alexstreltsov wrote:Yes, I mentioned the Bridged option in my original post,
Yes, I read that too. That's why I used your terms "most elegant"... :wink: because I read your post.

However:
alexstreltsov wrote:Wired connection in our "wireless" world... It doesn't seem like an elegant solution.
Requiring wi-fi wasn't mentioned in your first post. Changing the story on the fly makes it so a complete solution can't be presented.

And you did mention Bridged as an alternative:
alexstreltsov wrote:Alternative, a single Bridged Adapter may be used instead of the two adapters mentioned above, if it is acceptable for the VMs to be in the same network as the HM.
So from what info you provided in the OP, Bridged is the best solution.

With the new info in the 2nd post, NAT & Host-Only are the way to go.

How to set up the DNS is beyond me. But, this is your solution:
scottgus1 wrote:If you can [learn how to] take a group of physical PCs networked together through an unmanaged switch using dynamic IPs, and get them to talk to each other by their FQDN's, then you should be able to apply the same solution to the Host-Only network.
Virtualbox provides no special methods to do this DNS setup. Virtualbox only provides the Ethernet network 'hardware'. Web-search how to set up FQDN DNS in an Ethernet network running on an unmanaged switch, do the same thing to the Host-Only network, and it's done.
alexstreltsov
Posts: 3
Joined: 14. Jan 2023, 15:53

Re: What is the most elegant way to set up Host → VirtualBox VMs access via FQDNs?

Post by alexstreltsov »

scottgus1 wrote:Requiring wi-fi wasn't mentioned in your first post. Changing the story on the fly makes it so a complete solution can't be presented.
You are right! It is my fault.

In any case, as I understood, there are only two ways to get direct access to VMs in bridged networks or host-only networks using their FQDNs:
  1. 1. mDNS.
  • 2. DDNS server on the host machine.
scottgus1 wrote:Bridged is also a group of "PCs" attached to an unmanaged switch, just like a Host-Only network, or a group of real PCs. Whatever works on Bridged should also work on Host-Only.
It is true. I wrote this because my host machine did not see virtual machines in the host-only network, but after rebooting everything works properly.

I hope that an alternative to the Host-only adapter will be introduced as soon as possible :lol:

Thank you again for your help, scottgus1!
Post Reply