Introduction
VirtualBox Host-Only networking is the easiest way to create a private network between your host machine and one or more VMs. It is ideal for local lab environments, backend service testing, and safe experiments that should not be directly reachable from your LAN.
What Host-Only Means
Host-Only mode creates a virtual network where:
- Host can reach VM.
- VM can reach host.
- Other physical network devices usually cannot reach VM directly.
- VM has no internet unless you add another adapter.
This is different from:
- NAT mode (VM gets outbound internet, but inbound reachability is limited).
- Bridged mode (VM appears directly on LAN).
Basic Topology
Example addressing:
- Host-only adapter on host:
192.168.56.1/24 - VM1:
192.168.56.10/24 - VM2:
192.168.56.11/24
Step 1: Create/Verify Host-Only Adapter
In VirtualBox:
- Open
Tools->Network(orFile->Host Network Manager, depending on version). - Create host-only network if none exists.
- Confirm adapter IP and subnet.
Typical default is 192.168.56.1/24.
Step 2: Attach VM NIC to Host-Only Network
For each VM:
- Open VM
Settings->Network. - Enable Adapter 1.
- Set
Attached to:Host-only Adapter. - Select the host-only adapter you created.
Step 3: Configure VM IP
Inside Linux VM (temporary runtime config):
ip addr add 192.168.56.10/24 dev enp0s8
ip link set enp0s8 up
Or persistent config with your distro tool (Netplan, NetworkManager, ifcfg).
Step 4: Validate Connectivity
From host:
ping 192.168.56.10
From VM:
ping 192.168.56.1
If both work, host-only network is correct.
Add Internet While Keeping Host-Only (Dual Adapter Pattern)
Common lab setup:
- Adapter 1: NAT (internet access).
- Adapter 2: Host-Only (private host/VM traffic).
This gives internet plus stable private addressing.
Firewall Considerations
Do not disable firewalls globally. Instead, allow required traffic on host-only interface.
Linux VM example allowing ICMP and SSH from host-only subnet:
iptables -A INPUT -i enp0s8 -p icmp -j ACCEPT
iptables -A INPUT -i enp0s8 -p tcp --dport 22 -s 192.168.56.0/24 -j ACCEPT
Windows host may also need inbound ICMP/SSH exceptions depending on test type.
Common Troubleshooting
If host can ping VM but VM cannot ping host:
- Host firewall blocks inbound ICMP.
- Wrong host-only adapter selected on VM.
- VM route prefers wrong interface.
- Subnet mismatch.
If no ping either direction:
- Interface inside VM is down.
- IP address assigned to wrong NIC.
- Duplicate IP conflict.
- VirtualBox host-only driver issue.
Quick Diagnostic Commands
On VM:
ip addr
ip route
ss -tulpen
On host (Linux/macOS):
ip addr | grep 192.168.56
ping 192.168.56.10
Security and Lab Hygiene
Recommended lab practices:
- Keep host-only subnet private and non-overlapping.
- Use static IP reservations for predictable test scripts.
- Use snapshots before risky network changes.
- Document interface names per VM image.
Example Dev Environment Pattern
For local microservices testing:
- Host runs IDE and API client tools.
- VM runs database and message broker.
- Host communicates to VM over host-only IP.
- VM still gets package updates through NAT adapter.
This pattern mirrors production architecture while preserving local control.
Conclusion
VirtualBox Host-Only networking is a stable and safe way to connect host and VMs directly. Use host-only for private communication, and add NAT as second adapter when internet access is needed.
Most issues are interface selection, firewall filtering, or IP mismatches, all of which are easy to diagnose with a small checklist.
Comments