DEV Community

Cover image for VirtualBox Networking and Multi-VM Labs for DevOps Beginners
Ubayed Bin Sufian
Ubayed Bin Sufian

Posted on

VirtualBox Networking and Multi-VM Labs for DevOps Beginners

VirtualBox Networking

In this section we will discuss:

  • Various types of networking — NAT, Bridged, Host-Only — what they mean and when to use each
  • How multiple VMs connect to each other
  • How to troubleshoot issues where you can't reach the internet

A Computer Can Have More Than One Door to the Network

When we think about connecting a computer to the internet, we usually imagine just one connection — maybe Wi-Fi.

But a computer can actually have multiple network interfaces, and each one acts like its own separate door to the network.

Let me show you using my own laptop.

When I ran:

ip addr show
Enter fullscreen mode Exit fullscreen mode

I got this:

ip addr show

At first glance, this looks technical. But there's a simple story here.


Meet the Three Characters

1. lo — The Computer Talking to Itself

The loopback interface (lo) is special.

inet 127.0.0.1/8
Enter fullscreen mode Exit fullscreen mode

This is the famous localhost address. Think of it as your laptop looking into a mirror.

When an application talks to 127.0.0.1, it is not going out to the network — it is talking back to the same machine.


2. enp1s0 — The Unused Ethernet Port

2: enp1s0
state DOWN
NO-CARRIER
Enter fullscreen mode Exit fullscreen mode

This is my wired Ethernet adapter. It exists, but no cable is plugged in.

Imagine a door in your house that exists but is bolted shut — nobody can enter through it. That is why there is no IP address assigned here.


3. wlp2s0 — The Active Wi-Fi Connection

3: wlp2s0
inet 192.168.0.105/24
state UP
Enter fullscreen mode Exit fullscreen mode

This is my wireless adapter. It is connected to my home Wi-Fi, so my router assigned it an IP via DHCP:

192.168.0.105
Enter fullscreen mode Exit fullscreen mode

This is the address other devices on my home network can use to reach my laptop.

Summary of all networks


What if Both Were Connected?

Now imagine I plug in an Ethernet cable while Wi-Fi is still on.

Suddenly my laptop could look like this:

enp1s0  -> 192.168.0.110
wlp2s0  -> 192.168.0.105
Enter fullscreen mode Exit fullscreen mode

Same laptop. Two interfaces. Two IP addresses. Two different doors into the same machine.

Other devices could reach me using either address.


The Big Lesson

A computer is not assigned an IP address. An interface is assigned an IP address.

That is an important distinction. Your laptop may have:

  • one Wi-Fi adapter
  • one Ethernet adapter
  • a VPN tunnel
  • virtual machine adapters
  • docker bridges
  • loopback Each can have its own IP address.

So when someone says:

"What is your computer's IP?"

The more accurate question is:

"Which interface are you talking about?"

Glossary

  • A network interface is the part of a computer that allows it to communicate on a network.
  • A network adapter is the hardware (or virtual hardware) that provides that interface.
Hardware (adapter)  --->  OS sees it as  --->  Interface
Enter fullscreen mode Exit fullscreen mode

The Big Idea: Every VM is Just Another Machine on a Network

Think of your laptop as a small apartment building. VirtualBox creates multiple virtual "tenants" (VMs) inside it.

Each VM:

  • Has its own network card (adapter)
  • Connects to a "network type" you choose
  • Can have up to 4 network adapters (usually 1 is enough) adapters with network types

The key question is:

"Which network is this VM plugged into?"

That choice defines everything.


1. Host-Only Network (Private Lab Inside Your Laptop)

Concept

A Host-Only network is like building a private hallway inside your apartment building — only the residents (your VMs) and the landlord (your host machine) can use it. No one from outside can get in.

  • Only your host machine + VMs can talk to each other
  • No internet access by default
  • Completely isolated from the outside world Host only network

Example Setup

Host machine: 192.168.5.1
VM1:          192.168.5.2
VM2:          192.168.5.3
VM3:          192.168.5.4
Enter fullscreen mode Exit fullscreen mode

All machines can ping each other and share services internally — but none can reach the internet.

How It Works in VirtualBox

  1. Go to File → Tools → Network Manager
  2. Create a new Host-Only network
  3. VirtualBox creates a virtual adapter (like vboxnet0) vboxnet0 ip addr show
  4. Your host gets an IP like 192.168.5.1
  5. Attach VMs to Host-Only Adapter Attach VMs

Use Case

  • Testing microservices locally
  • Simulating private networks
  • Database + backend interaction in isolation

2. NAT Network (Private Network + Internet Access)

Concept

A NAT Network is like that same private hallway — but now there's a shared exit door that leads outside. The tenants can talk to each other and get to the internet, but strangers still can't walk in uninvited.

  • VMs can talk to each other
  • VMs can access the internet
  • External systems still cannot directly access VMs

How It Works

When a VM sends a request out to the internet:

  1. VM sends a packet with its private IP (e.g. 10.0.2.4)
  2. VirtualBox's NAT engine replaces it with the host's IP
  3. Request goes to the internet
  4. Response comes back to the host
  5. NAT engine forwards it back to the correct VM This is called Network Address Translation (NAT).

Example

VM1 → 10.0.2.4
VM2 → 10.0.2.5
VM3 → 10.0.2.6
Enter fullscreen mode Exit fullscreen mode

All share internet access and can communicate internally.

NAT network

Setup

  1. Go to File → Tools → Network
  2. Create a NAT Network Create a NAT Network
  3. Attach VM → Network → NAT Network Attach VM to NAT network

Use Case

  • Running development environments with internet access
  • Package installs (apt, npm, pip)
  • APIs + database testing with external services

3. NAT (Default VM Mode)

Concept

This is similar to NAT Network but simpler and more isolated. Each VM gets its own mini-router — it can call out to the internet, but it cannot talk to other VMs by default.

Think of each tenant having their own private exit, but no shared hallway between them.

NAT

Key Difference vs NAT Network

Feature NAT NAT Network
Internet access
VM-to-VM communication
Shared network

NAT diagram

Use Case

  • Single VM development
  • Safer isolation
  • Quick setup without networking complexity

4. Bridged Network (VM Becomes a Real Machine on Your LAN)

Concept

Bridged networking is the most open mode. Your VM stops being a hidden tenant and moves out onto the street — it becomes a fully visible member of your home network, just like your phone or any other device.

The VM behaves like a real computer plugged into your router.

Example

Router:  192.168.1.1
Laptop:  192.168.1.10
Phone:   192.168.1.20
VM:      192.168.1.30   ← your router sees this as a real device
Enter fullscreen mode Exit fullscreen mode

Overview of Bridged adapter

Bridged adapter

What Happens Internally

  • VM gets an IP from your router via DHCP
  • Same subnet as your laptop
  • Fully visible to other devices on the network

Use Case

  • Hosting services (web servers, APIs)
  • Testing real network behavior
  • Accessing the VM from another machine on your LAN

Internet Connectivity Summary

Mode Internet Access
NAT ✅ Via host as gateway
NAT Network ✅ Via host as gateway
Bridged ✅ Via router directly
Host-Only ❌ No internet by default

internet connectivity
Screenshot taken from YouTube video

If Host-Only Needs Internet

You have two options:

Option A: Enable IP forwarding on the host — make your laptop act like a router.

Option B (simpler): Add a second adapter to each VM:

  • Adapter 1 → Host-Only (private network)
  • Adapter 2 → NAT (internet) This is the most common real-world setup for home labs.

5. Port Forwarding (Access VM Services from Outside)

Concept

Port forwarding is like setting up a concierge at the front desk of your building. When a visitor arrives and asks for a specific service, the concierge knows exactly which apartment to send them to.

"If someone knocks on port 8080, send them to the web server in VM1."

Example — Web Server

Host Port 8080 → VM Port 80
Enter fullscreen mode Exit fullscreen mode

Now visiting http://localhost:8080 forwards to the web server running inside your VM.

Example — SSH

Host Port 2222 → VM Port 22
Enter fullscreen mode Exit fullscreen mode
ssh user@localhost -p 2222
Enter fullscreen mode Exit fullscreen mode

You can SSH into the VM without even knowing its internal IP.

Port forwarding

Use Case

  • Accessing web apps inside a NAT VM
  • Debugging microservices
  • Running multiple VMs with different exposed ports

Working with Multiple VMs: Cloning and Snapshots

So far, we've explored the different networking modes in VirtualBox. Now let's look at how to efficiently create multiple VMs, connect them together, and use snapshots to experiment safely.


Creating Multiple VMs with Cloning

When building a lab, you'll often need several VMs that are nearly identical — like printing copies of the same blueprint rather than drawing each one from scratch.

The common approach:

  1. Create and configure one base VM
  2. Install required software and updates
  3. Use it as a template
  4. Clone it as many times as needed

How to Clone a VM

  1. Shut down the VM
  2. Right-click the VM in VirtualBox
  3. Select Clone
  4. Enter a name for the new VM
  5. Choose the clone type

Note: The Clone option is only available when the VM is powered off.

How to Clone a VM

Full Clone vs Linked Clone

Full Clone — A completely independent copy. Like photocopying a document: the copy stands on its own.

  • ✅ Fully self-contained, easy to move between computers
  • ❌ Uses the same disk space as the original

Linked Clone — Shares the original's virtual disk and only stores changes. Like a shortcut that points back to the original.

  • ✅ Much smaller, faster to create
  • ❌ Depends on the parent VM; can't be moved easily

When to Use Each

Scenario Recommended
Learning labs Linked Clone
Temporary testing Linked Clone
Long-term VM Full Clone
Moving VMs between computers Full Clone

For most home labs, Linked Clones are sufficient.


Connecting Multiple VMs Together

Say we've cloned our base VM and now have VM1 and VM2. We want:

  • VM1 ↔ VM2 communication
  • Internet access for both The cleanest solution: two network adapters per VM.

Adapter 1: NAT

Gives each VM internet access — for downloading packages, updates, and calling external services.

Adapter 2: Host-Only Network

Creates a private channel between all VMs and the host.

Host Machine  → 192.168.57.1
VM1           → 192.168.57.3
VM2           → 192.168.57.4
Enter fullscreen mode Exit fullscreen mode

Setting Up the Host-Only Network

  1. Open File → Host Network Manager
  2. Click Create
  3. Enable DHCP if desired
  4. Save the network VirtualBox creates a virtual network (vboxnet1) with an address range like 192.168.57.0/24.

Attaching VMs to the Host-Only Network

For each VM:

  1. Open VM Settings → Network
  2. Enable Adapter 2
  3. Select Host-Only Adapter
  4. Choose the newly created network

Verifying Connectivity

Once both VMs are running:

Check IP addresses:

ip addr
Enter fullscreen mode Exit fullscreen mode

You should see a second interface with an IP like 192.168.57.3 or 192.168.57.4.

Test VM-to-VM communication:

# From VM1
ping 192.168.57.4

# From VM2
ping 192.168.57.3
Enter fullscreen mode Exit fullscreen mode

Test internet access:

ping google.com
Enter fullscreen mode Exit fullscreen mode

All three should work.


Choosing the Right Networking Mode

A quick reference:

Requirement Recommended Mode
Internet only NAT
VM-to-VM + Internet NAT Network
VM-to-VM only Host-Only
VM visible on LAN Bridged
Private network + Internet Host-Only + NAT

Using Snapshots

Think of snapshots as save points in a video game. Before you attempt a risky boss fight (a major system change), you save. If things go wrong, you reload and try again.

Why Snapshots Are Useful

Before you:

  • Upgrade software
  • Install packages
  • Modify configurations
  • Experiment with new tools Take a snapshot. If something breaks, restore it in seconds.

Creating a Snapshot

  1. Select the VM → open the Snapshots view
  2. Click Take Snapshot
  3. Give it a meaningful name (e.g. Good State)

Example

mkdir -p /opt/app
echo "Example File" > /opt/app/example.txt
Enter fullscreen mode Exit fullscreen mode

Everything works. Take a snapshot named Good State.

Now simulate an accident:

echo "corrupted data" > /opt/app/example.txt
Enter fullscreen mode Exit fullscreen mode

Restoring a Snapshot

  1. Power off the VM
  2. Open Snapshots
  3. Right-click the snapshot → Restore After booting, the VM returns exactly to where it was. The original file is back.

Cloning from a Snapshot

You can also clone directly from a snapshot — useful for:

  • Testing multiple software versions side by side
  • Comparing configurations
  • Building temporary environments from a known-good state

Best Practices

Use clones for reusability — configure one solid base VM, clone it whenever you need a fresh machine.

Use Linked Clones for labs — they save significant disk space.

Take snapshots before major changes — OS upgrades, kernel updates, database migrations, large installs.

Use NAT + Host-Only together — this combination gives you internet access and VM-to-VM communication, which covers most lab scenarios.


Final Thoughts

VirtualBox becomes significantly more powerful once you combine cloning, multiple network adapters, and snapshots. Together, they let you build realistic multi-machine environments on a single laptop — and experiment freely, knowing you can always recover.


This is part of my DevOps Prerequisite series:


Disclaimer: I have used GPT 5.5 & Claude Sonnet 4.6 (Low) for writing the topics, GPT 5.5 & Gemini Nano for content and cover image generation respectively.

Reference:
💡 Want a visual walkthrough? This video does a great job explaining the basics covered here. Use it as a supplement — not a replacement:

Top comments (0)