No Internet Access on VMs in NAT Network in VirtualBox

Why not working?

In 16.04 (and probably 14.04) the NAT Network feature of the main packaged version of VirtualBox (5.0.36) is bugged.

Check it!

You can check it yourself: if the ls /usr/lib/virtualbox/VBoxNetNAT executable is present, then you may have some other kind of issue.

Fix it!

This bug is fixed in newer versions. So you should install a new version:

Remove old version

For example if you installed using apt you could run:

sudo apt remove virtualbox --auto-remove

Install new version

The fix is available for newer versions (Ubuntu yakkety+). For older versions:

  • Visit the virtualbox.org, and download the newest version manually
  • OR
  • Use the following script:

    # add the official repository
    wget -q -O - https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo apt-key add -
    echo deb http://download.virtualbox.org/virtualbox/debian `lsb_release -cs` non-free contrib | sudo tee /etc/apt/sources.list.d/virtualbox.org.list
    # install the newer version
    sudo apt install virtualbox-5.1
    

I ran into this using VirtualBox 5.0.40 from the default apt repository. To get around it, I configured each VM to use two network interfaces.

  • Adapter 1: Bridge Addapter (to your real nic)
  • Adapter 2: NAT Network (of your choice)

Under the guets OS (Ubuntu 16.04), you will need to tweak /etc/network/interfaces in order for the second interface to show up. In my case, I needed VMs to use static IPs inside the NAT Network, so this is what I got.

## Bridge to Internet
auto enp0s3
iface enp0s3 inet dhcp

## NAT Network among VMs
## Static is optional
## DHCP if you don't need it
auto enp0s8
iface enp0s8 inet static
  address 10.10.11.100
  netmask 255.255.255.0

This, of course, assumes my NAT Network uses the subnet 10.10.11.0/24. Adapt numbers to your scenario or just leave it to dhcp, as you wish.

NOTE: One important thing to note in the static config is that, for this particular scenario, you CANNOT assign it a default gateway. Giving enp0s8 a default (like 10.10.11.1) will cause the OS to create a route to this gateway and that route can also screw up your internet access as well. You should only need to do that when this particular interface needs routes to other networks, aside from the one configured to it.

To find out interface names assigned by Ubuntu for your environment, you can dmesg | grep eth.

enter image description here


According to VirtualBox manual, these are the network possibilities for your VMs:

  • NAT: Internal network between VM and host. Besides you can access to the Internet. Two or more VMs in NAT mode don't have connectivity among them, only with the host and Internet.

  • Internal: All VMs with this configuration will have connectivity among them but not with the host nor Internet.

  • Host only: A virtual network will be created between the host and all the VMs with this configuration, but you will have no Internet access.

  • NAT Network: You can reach all VMs in the same pre-defined NAT network and the host, but you won't be able to connect to Internet.

  • Bridged: Your VM will be in the same network that your host as if it were other computer/server in this network, and thus, it will have Internet acces if your host has.

  • Generic: Advanced and more specific configuration rarely used.

So, if you want to create an internal network with connectivity to the host choose NAT Network, but notice that you will have no Internet access. NAT is set only when you just want Internet access from your VM and nothing else.

However none of these settings are ok with you if you want to have either connectivity between both VMs and the Internet. As far as I know, your only choice is to configure both VMs in bridged mode, so they will be 'different' computers in you host network and you will be able to ping them all and the Internet from any of them.

On the other hand, it seems that you clonned one VM from the other because both machines have the same MAC address (HWaddr in ifconfig command info), be aware that you should check the checkbox that reads "Reinitialize the MAC address of all network cards" when clonning. Two devices with the same MAC address always creates problems.

I am not an expert in VirtualBox so maybe other users can tell you other posible configurations to get what you want. I hope you find this information useful.

For more information you can read this.


This might be a bug in VirtualBox. I've experienced the same (Ubuntu 16.04.2 LTS, VirtualBox 5.0.32_Ubuntu r112930): Set up a NAT Network, configured that for two Ubuntu VMs. Each VM could ping / SSH into the other, and via port forwardings I could SSH from the host into each VM. But no Internet access from inside the VMs. A colleague tried the same with a Windows host, VirtualBox (unknown version), and the same VMs, and it worked.

As a workaround, I've configured a second network card for each VM: The first one using NAT to access the Internet, the second using "NAT Network" to access the other guest(s). I had to set up the SSH port forwarding on the first (NAT) card, and configure a different SSH port on one VM (i.e. 2222 -> 22 on VM1, 2223 -> 23 on VM2).

Based on the documentation, both NAT and NAT Network should be able to access the Internet. The difference is that the first has segregated host ↔ guest connections, so guests cannot access each other, only the host. The latter pools all guests into a single network (and provides services such as DHCP), so that they can access each other.