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
I got this:
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
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
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
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
This is the address other devices on my home network can use to reach my laptop.
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
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
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)
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
Example Setup
Host machine: 192.168.5.1
VM1: 192.168.5.2
VM2: 192.168.5.3
VM3: 192.168.5.4
All machines can ping each other and share services internally — but none can reach the internet.
How It Works in VirtualBox
- Go to File → Tools → Network Manager
- Create a new Host-Only network
- VirtualBox creates a virtual adapter (like
vboxnet0)
- Your host gets an IP like
192.168.5.1 - Attach VMs to Host-Only Adapter
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:
- VM sends a packet with its private IP (e.g.
10.0.2.4) - VirtualBox's NAT engine replaces it with the host's IP
- Request goes to the internet
- Response comes back to the host
- 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
All share internet access and can communicate internally.
Setup
- Go to File → Tools → Network
- Create a NAT Network
- Attach VM → Network → 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.
Key Difference vs NAT Network
| Feature | NAT | NAT Network |
|---|---|---|
| Internet access | ✅ | ✅ |
| VM-to-VM communication | ❌ | ✅ |
| Shared network | ❌ | ✅ |
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
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 |

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
Now visiting http://localhost:8080 forwards to the web server running inside your VM.
Example — SSH
Host Port 2222 → VM Port 22
ssh user@localhost -p 2222
You can SSH into the VM without even knowing its internal IP.
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:
- Create and configure one base VM
- Install required software and updates
- Use it as a template
- Clone it as many times as needed
How to Clone a VM
- Shut down the VM
- Right-click the VM in VirtualBox
- Select Clone
- Enter a name for the new VM
- Choose the clone type
Note: The Clone option is only available when the VM is powered off.
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
Setting Up the Host-Only Network
- Open File → Host Network Manager
- Click Create
- Enable DHCP if desired
- Save the network
VirtualBox creates a virtual network (
vboxnet1) with an address range like192.168.57.0/24.
Attaching VMs to the Host-Only Network
For each VM:
- Open VM Settings → Network
- Enable Adapter 2
- Select Host-Only Adapter
- Choose the newly created network
Verifying Connectivity
Once both VMs are running:
Check IP addresses:
ip addr
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
Test internet access:
ping google.com
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
- Select the VM → open the Snapshots view
- Click Take Snapshot
- Give it a meaningful name (e.g.
Good State)
Example
mkdir -p /opt/app
echo "Example File" > /opt/app/example.txt
Everything works. Take a snapshot named Good State.
Now simulate an accident:
echo "corrupted data" > /opt/app/example.txt
Restoring a Snapshot
- Power off the VM
- Open Snapshots
- 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:
- DevOps Prerequisite #1: Linux Basics You Actually Need
- Build Your Own Lab: Virtualization for DevOps Beginners
- VirtualBox Networking and Multi-VM Labs for DevOps Beginners (this post)
- Why Vagrant Still Matters (and When It Doesn't) (next)
- Networking for DevOps: The Only Concepts You Need
- YAML Explained for Future DevOps Engineers
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)