VirtualBox Networking with Multiple Adapters

For some people, VirtualBox does everything smoothly. It's stupid easy. For others, setting up multiple networking adapters is the hardest frigging thing ever. [email protected]&!

What I've found with Linux is that there's always a way forwards. That is true here, so I want to share how I dealt with some of my previous troubles.

I highly recommend reading this page first to learn the basics of VirtualBox networking. If you're having problems yourself, hope it helps.

Basic NAT Setup

Before we dive in, I should cover some terminology. There are three parts required for a network interface to be working. There must be a physical connection, called the physical interface. It must be administratively enabled, so it can be used. Finally, there must be a data link set up, so there is something to carry data over the physical interface.

Now let's say I'm trying to get NAT working, but it's not working. Wha?

Assume enp0s3 is the NAT network. First, let's start with the good, old ifconfig command:

~$ ifconfig

enp0s3    Link encap:Ethernet  HWaddr 08:00:27:29:17:05

Because enp0s3 is listed, we know two things. We know that our virtual machine sees the physical NAT interface, aka enp0s3. We also know that the interface is administratively enabled.

However, ifconfig does not display data link info. We need another tool to check that the data link is OK.

Here we'll use nmcli, the network management client. For those new to nmcli, see the great, short intro here.

Let's check the state of the data link for enp0s8:

~$ nmcli device
enp0s3  ethernet  disconnected  --
lo      loopback  unmanaged     --

This shows us there is no data link. Thankfully it's simple to set up:

~$ nmcli device connect enp0s3
Device 'enp0s3' successfully activated with '1185ac66-bab7-3f2a-8cb2-17a65e5e3b9d'.

To be safe, let's double check the state of the data link:

~$ nmcli device
enp0s3  ethernet  connected     Wired connection 2
lo      loopback  unmanaged     --

NAT has everything up and running! Wo!

NAT + Internal

Moving on, let's attach an internal network adapter to our virtual machine. enp0s8 is the internal network.

It would seem, just like NAT, we would want to run:

~$ nmcli device connect enp0s8
... waiting ...
... 4 years later ...

However, enp0s8, is waiting to be assigned an IP address:

~$ nmcli device
DEVICE  TYPE      STATE                                  CONNECTION
enp0s3  ethernet  connected                              Wired connection 2
enp0s8  ethernet  connecting (getting IP configuration)  Wired connection 1
lo      loopback  unmanaged                              --

We need to provide enp0s8 with one. The short command is:

~$ sudo ifconfig enp0s8 up

This command assigns a static IP to the enp0s8 interface. The nice thing is, this always establishes the data link for enp0s8, so there's no need for nmcli here.

In fact, starting the data link through nmcli can sometimes disconnect data links for other network interfaces. I'm unsure why this happens, just make sure to only use ifconfig here.


That's the gist of it! To attach other network adapters, follow the above instructions. host-only networks work like internal networks, while everything else works like NAT.

Be warned, some distro's dislike various combinations of network adapters. For example, Kali doesn't like bridged+NAT. I had to learn that the hard way.

Shout out to socratis from irc #vbox, and squib0 of irc #cisco! squib0 helped clarify some of these details.