16

I have created a a NAT Network in VirtulBox 5 In Ubuntu 14.04 LTS with following settings

Natework Name : NatNetwrok1
Network CIDR: 10.0.2.0/24
Support DHCP :enabled
Support IPv6 :disabled
without any port forwarding

Additionally I have two VMs (Both Xubuntu clones), I have set the Network settings to enable two NICs on each of the VM with following settings in all four adapters:

Attached To : “NAT Network”
Name : “NatNetwrok1”

When I run both VMs I can see following settings on running ifconfig command

ifconfig results on Xubuntu1

eth0      Link encap:Ethernet  HWaddr 08:00:27:00:8c:03  
          inet addr:10.0.2.9  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe00:8c03/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:43 errors:0 dropped:0 overruns:0 frame:0
          TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12133 (12.1 KB)  TX bytes:8517 (8.5 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:9e:20:e8  
          inet addr:10.0.2.8  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe9e:20e8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:43 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:10294 (10.2 KB)  TX bytes:8798 (8.7 KB)

ifconfig results on Xubutracentu2

eth0      Link encap:Ethernet  HWaddr 08:00:27:00:8c:03  
          inet addr:10.0.2.9  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe00:8c03/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:43 errors:0 dropped:0 overruns:0 frame:0
          TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12133 (12.1 KB)  TX bytes:8517 (8.5 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:9e:20:e8  
          inet addr:10.0.2.8  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe9e:20e8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:43 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:10294 (10.2 KB)  TX bytes:8798 (8.7 KB)

Ping between these 4 IPs works fine
But I can not access Internet on either of these VMs
While if o change “NAT Network” to “NAT” I can access the network but it seems the become part of different virtual network and I can not ping them from each other
Can anybody help me in identifying and fixing problem

Can anyone also explain whats difference between NAT and NAT Network

  • Same issue ... Could someone help ? – monitor35 May 4 '16 at 12:28
  • I recently ran into this problem using virtual box 5.0.40 from the default ubuntu repo. To get around it, I configured each VM with two interfaces. One with an internal NatNetwork, and the other using bridge mode. Under the guest OS (ubuntu 16.04), you will need to tweak /etc/network/interfaces in order for the second interface to show up in the guest. That made it possible for each VM to be in the internal NAT and have access to the internet at the same time. – JulioHM Jun 13 '17 at 17:41
7

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
    
| improve this answer | |
  • 1
    If you have a previous version of virtualbox installed, make sure you also uninstall virtualbox-dkms for this fix to work. Otherwise, you may still be stuck without internet – Barak Itkin May 7 '18 at 20:57
6

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.

| improve this answer | |
  • 3
    It is not true that NAT Network will prevent your guests from connecting to the internet. I can connect to the internet from VM guests on a NAT Network. Per the last comment on forums.virtualbox.org/viewtopic.php?f=3&t=69504, "NAT mode means each VM is isolated behind its own router... NAT Network is the same as NAT except that you can have several VM connected to the same internal router." – eebbesen Dec 4 '16 at 12:24
6

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

| improve this answer | |
  • Mine worked better when I used 'dhcp' for both eth0 and eth1. It just automatically assigned 10.0.2.15 for NAT and my public internet eth1 doesnt have an IP, but I can ping the internet from the VM! – Milean Sep 11 '18 at 12:42
2

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.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.