DEV Community

Cover image for The Superior Way to make VMs communicate with each other as well as host, with internet access
Shoban Chiddarth
Shoban Chiddarth

Posted on

The Superior Way to make VMs communicate with each other as well as host, with internet access

Introduction

On December 1, 2025, I made a LinkedIn post about setting up inter-VM networking with 3 VMs (a DHCP server, a web server and a client). The full details and a technical document are available in the post if you want to check it out.

The way I set up 3 VMs for inter-VM networking with internet access is

  • VMs are set to use "Virtualbox Host Only Ethernet Adapter"
  • Internet is shared to the adapter using Windows proprietary ICS ("Internet Connection Sharing") from Control Panel. It worked in a Windows host (I was temporarily using Windows at that time) because internet sharing is fully handled by Windows, and the inter-VM networking worked with no issues.

Now I am using a Linux host and need to set up inter-VM networking for a project, the same thing is not possible as ICS is a Windows proprietary service. A similar solution will require turning the host into a router and manually managing firewall entries and route tables every time a network segment is created or removed - invasive and hard to cleanly reverse. The other option is attaching two adapters to each VM: one for inter-VM and host communication, another for internet access - which gets complicated across several VMs and can cause issues with desktop environments and network managers.

There is a superior way to achieve the following:

  • VMs can communicate with each other
  • Host can communicate with VMs and vice versa
  • VMs can access the internet
  • Host does not need to be converted to a router
  • 2 or more adapters do not need to be attached to every single VM
  • Nothing is permanently changed on the host that requires manual intervention to revert, everything stays in Virtualbox and goes away when you delete them

The solution is to run pfSense in a VM that acts as the router between network adapters, keeping everything contained inside VirtualBox.

Overview

Network diagram showing pfSense VM with WAN adapter (Bridged/NAT/NAT Network) connected to the internet, and LAN adapter (VBHOEA) connecting to a Host Only Network shared with other VMs

The setup is simple: install pfSense inside a VM and attach two adapters to it.

The first adapter connects pfSense to the internet. You can use Bridged, NAT, or NAT Network - all three work as long as the host has internet access. (Bridged gives pfSense a real IP on your physical LAN; NAT and NAT Network are simpler and work without touching your router).

For more information on VirtualBox virtual networking, see the manual.

The second adapter is a VirtualBox Host Only Ethernet Adapter attached to a specific Host Only Network. This becomes the LAN side.

For every other VM in your lab, attach a single VirtualBox Host Only Ethernet Adapter and select the same Host Only Network you assigned to pfSense's LAN adapter.

In pfSense, assign the first adapter as WAN and the Host Only Ethernet Adapter as LAN.

Disable the VirtualBox built-in DHCP server for that Host Only Network, and configure DHCP inside pfSense instead.

Always boot pfSense before your lab VMs - it handles DHCP and routing for the entire network.

Steps

Install pfSense on VirtualBox

  1. Download the pfSense ISO file from Netgate Shop
  2. Click "New" on Virtual Box and fill in the name of the OS, select the ISO file.
  3. Select OS: "BSD"; Distro: "FreeBSD"; OS Version: "FreeBSD 64 bit";

001

  1. Select 2GB RAM and 4GB Hard Disk

002

  1. Click on "Start" and then install the OS. By default, Virtualbox assigns the "NAT" adapter as the only interface. That is fine for now. Select that as the WAN interface in the installation process. For installing the OS, accept defaults for everything else.
  2. After installation is over, shut the VM down instead of rebooting.
  3. Go to VM's settings -> Storage and remove the ISO file.

003

  1. Click "Ok" and then boot the VM up.

004

If it boots up to this state then it means that it is successful. Now you can reset the admin account and password, then shut it down.

Configuring interfaces on pfSense

  1. Go to Virtualbox Networks and select "Host Only Networks". Create a new Host Only Network if you do not want to use the default. Note the subnet/CIDR block.
  2. Go to Machines -> pfSense VM settings -> Network and enable a second adapter, and set it to VirtualBox Host Only Ethernet Adapter and then select the Host Only Network you wish to use it. Make sure to select "Allow All" in promiscuous mode. This allows pfSense to forward traffic on behalf of other VMs.

005

  1. Click on "OK" and boot it up again.

006

  1. Select "1" to configure interfaces. Then select no for VLANs, assign em0 as WAN interface and then em1 as LAN interface. Then confirm it.

007

  1. Select 2 to set interface IP addresses. We need a static IP on the LAN interface because pfSense will be our DHCP server. Make sure you are setting up an IP that does not clash with the host, and lies in the same subnet as the VirtualBox Host only network, then choose to enable DHCP server on LAN. (IPv6 is optional). > Note: To find the host's IP on that network, go to VirtualBox Manager -> Networks -> Host Only Networks and select your network.

008

009

  1. After it is done, access the static IP you set via a web browser from the host. Enter the username admin and the password you set up earlier.

pfSense web configuration

  1. Click next on the welcome messages and on the initial configuration, enter the appropriate values as shown in the image. Make sure to set up a valid upstream DNS resolver.

010

  1. Leave the timeserver as is, and choose your timezone.

011

  1. Click next and you will be asked to configure WAN and LAN interfaces. Change nothing as you already set this one up.
  2. Set the admin account password again when it prompts you to and then reload and login. At this point pfSense is fully operational. Any additional configuration such as firewall rules or DNS overrides can be done from this interface.

VM Intercommunication and Verification

Create VMs as needed. Make sure to attach a VirtualBox Host Only Ethernet Adapter and select the Host Only Network you set up pfSense in.

012

Set up a web server VM with a static IP and a test page to verify host-to-VM communication.

013

Set up a client VM in the same adapter and network, configured as a DHCP client. Verify that it receives an IP from pfSense.

014

From the client VM, access the web server using its IP. Verify that VM-to-VM communication works.

015

Verify internet access from the client VM.

016

Note that the client VM has only one interface attached - the Host Only Ethernet Adapter with the relevant Host Only Network selected. Through this single adapter, the VM can reach other VMs on the same network, the host, and the internet.

Conclusion

The result is a clean, self-contained lab network: VMs can communicate with each other and the host, have full internet access, and the host requires no permanent configuration changes. pfSense handles routing, DHCP, and DNS entirely within VirtualBox.

This setup works as a solid foundation for any multi-VM lab that needs real network services, making it particularly useful for cybersecurity home labs.

Top comments (0)