VirtualBox Networking Setup: Bridged vs NAT Configuration for Host-Guest Communication and Internet Access


4 views

When setting up networking in VirtualBox, you essentially have four adapter types to choose from:

  • NAT (Network Address Translation)
  • Bridged Networking
  • Internal Network
  • Host-only Networking

For your specific requirements (host-guest communication + internet access), I recommend using two virtual network adapters:

  1. Adapter 1: NAT (for internet access)
  2. Adapter 2: Host-only (for host-guest communication)

1. Configure VirtualBox Global Preferences:

Go to File → Preferences → Network → Host-only Networks. Add a new host-only network (typically vboxnet0).

2. Configure VM Network Settings:

VBoxManage modifyvm "YourVMName" --nic1 nat
VBoxManage modifyvm "YourVMName" --nic2 hostonly --hostonlyadapter2 vboxnet0

3. Configure Guest OS Networking:

In your Ubuntu guest, edit /etc/network/interfaces:

# The NAT interface (for internet)
auto enp0s3
iface enp0s3 inet dhcp

# The host-only interface
auto enp0s8
iface enp0s8 inet static
address 192.168.56.10
netmask 255.255.255.0

Verify internet access:

ping 8.8.8.8
curl google.com

Test host-guest communication:

From host (Windows):

ping 192.168.56.10

From guest (Ubuntu):

ping 192.168.56.1  # Default host-only adapter IP

To access an Apache server running on the guest:

  1. Install Apache on Ubuntu guest:
  2. sudo apt install apache2
    
  3. Edit Apache config to listen on host-only interface:
  4. Listen 192.168.56.10:80
    
  5. From host browser, access: http://192.168.56.10
  • Check VirtualBox network adapter names match guest OS configuration
  • Verify firewall settings on both host and guest
  • Restart networking services after configuration changes
  • sudo systemctl restart networking
    

For simpler setups, you might consider using bridged networking alone:

VBoxManage modifyvm "YourVMName" --nic1 bridged --bridgeadapter1 "YourHostNetworkAdapter"

This gives the guest an IP in your local network, allowing both internet access and host-guest communication.


When working with VirtualBox (version 4.0.2 in this case), setting up proper networking between host (Windows 7) and guest (Ubuntu 10.10) requires understanding three key scenarios:

  • Bidirectional internet access for both systems
  • Ping connectivity between host and guest
  • Service accessibility (like Apache web server)

The most effective setup combines two network adapters in the guest machine:

  1. Adapter 1: NAT (for internet access)
  2. Adapter 2: Host-only (for host-guest communication)

1. Setting Up NAT for Internet Access

In VirtualBox Manager:

1. Right-click your VM → Settings → Network
2. Enable Adapter 1
3. Attached to: NAT
4. Advanced → Promiscuous Mode: Allow VMs

2. Configuring Host-only Network

First, ensure you have a host-only network created:

1. File → Host Network Manager → Create
2. Set IPv4 address (e.g., 192.168.56.1)
3. Enable DHCP server if needed

Then configure the guest's second adapter:

1. In VM Settings → Network → Adapter 2
2. Enable Adapter 2
3. Attached to: Host-only Adapter
4. Name: vboxnet0 (or your created network)

In Ubuntu guest, edit /etc/network/interfaces:

# The NAT interface (usually eth0)
auto eth0
iface eth0 inet dhcp

# The host-only interface (usually eth1)
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0

Restart networking:

sudo /etc/init.d/networking restart

From host command prompt:

ping 192.168.56.101

From guest terminal:

ping 192.168.56.1
ping google.com

On guest Ubuntu:

sudo apt-get install apache2

From host browser, access: http://192.168.56.101

  • Check VirtualBox network filters if ping fails
  • Verify guest firewall isn't blocking connections
  • Use ifconfig to confirm IP assignments
  • For Windows hosts, disable public network firewall for host-only network