How-to: Configure VirtualBox Networking Adapters (2021)

Updating one of the most popular series of posts in this blog, this is a new how-to: configure VirtualBox networking adapters. Taken from the book The VirtualBox Networking Primer - Connecting and Configuring Virtual Machines, we'll update some more VirtualBox networking topics in future posts.

Networking in VirtualBox is powerful, flexible and capable of a full range of functions. The price of all this is complexity. Eight network adapters, six emulated hardware network interface controllers (NIC’s), seven network modes, port forwarding plus firewall rules – it can quickly turn into a baffling maze when all you want is to get some packets of data from one machine to another.

Let’s get familiar with the network settings for a virtual machine within the VirtualBox Manager.

Figure: Virtual machine network settings

From the VirtualBox Manager, you can go into any of your virtual machine settings, select the Network page and move through the Adapter tabs for configuring networking for that machine.

Left to right are four tabs for the first four of the possible eight network adapters. The character and operation of any virtual network adapter is determined by the combination of the network mode – what the adapter is Attached to – and network interface controller (NIC) – the Adapter Type.

The choice of networking mode depends on how you want to connect your virtual machine and whether you want other machines on your own or external networks to see it.

Figure 3: Network mode Attached to drop-list

Figure: Network mode Attached to drop-list

You can configure each network adapter in your virtual machine to operate in one of the following modes:

  • Not Attached
  • Network Address Translation (NAT)
  • NAT Network
  • Bridged Networking
  • Internal Networking
  • Host Only Networking
  • Generic Networking

Select the network mode according to the use case in which the virtual machine interacts with virtual and physical networks. Network modes are key to understanding networking in VirtualBox. We will run through these individually soon.

The Adapter type represents our virtual network interface controllers, in which industry-standard, real-world hardware is emulated in software.

Figure 4: Network adapter Adapter Type drop-list

Figure 4: Network adapter Adapter Type drop-list

Each network adapter can be emulated as the appropriate model of real-world Intel and AMD network interface controllers. Those hardware types are:

  • AMD PCNet PCI II (Am79C970A)
  • AMD PCNet FAST III (Am79C973) – this is the default
  • Intel PRO/1000 MT Desktop (82540EM)
  • Intel PRO/1000 T Server (82543GC)
  • Intel PRO/1000 MT Server (82545EM)
  • Paravirtualized network adapter (virtio-net)

The availability of adapter types comes down to whether the Guest operating system has drivers for that NIC. VirtualBox will suggest a list of NIC’s based on the Guest operating system specified during creation of the virtual machine. You rarely need to modify this. We’ll go through the properties of these NIC’s later.

Figure 5: Network adapter advanced properties

Figure: Network adapter advanced properties

VirtualBox network adapter advanced settings allow you to qualify the Attached to network mode and Adapter Type by changing the MAC address of each virtual NIC, and plugging or unplugging the virtual network cable – Cable Connected. Port forwarding can be configured for external access to virtual machines whose network adapters operate in NAT or NAT Network modes.

Comparison of VirtualBox Network Modes

Before we go through each of the available networking modes, let’s look at a quick comparison of the types of access they support.

You should consider the use case for the Guest(s) you are running and determine what is the best single or combined networking option to support the network access needed. Depending on the type of access you should select one or more adapters with the appropriate network network modes. The table below should help.




Access

Network mode Guest to other Guests Guest to host Host to Guest Guest to external network External network to Guest
Not attached No No No No No
Network Address Translation (NAT) No Yes Port forward Yes Port forward
NAT Network Yes Yes Port forward Yes Port forward
Bridged networking Yes Yes Yes Yes Yes
Internal networking Yes No No No No
Host-only networking Yes Yes Yes No No

Figure 6: Comparison of network modes

The beauty of VirtualBox networking is that it can be modified and added to. It is not a disaster if it is not ‘right first time.’ Indeed, as requirements change – say you need to add additional services or allow external access – you can modify the networking support without having to junk or rebuild the virtual machine. It’s just like adding a network card and extra protocols to a physical machine.

Practice: Network Adapter Configuration

You can configure up to four Network Interface Controllers from the Network tab of the virtual machine settings. An additional four NIC’s can be configured from the command line using the VBoxManage modifyvm command in a terminal session.

When you reach five or more NIC’s for one virtual machine, you are either building an industrial strength production environment, or your experiments in networking are going seriously deep. Either way, you’re probably going beyond the scope of this primer.

Think of the first four adapters provided in the desktop interface as empty controller slots in the virtual machine. To ‘add’ a network adapter to your virtual machine just select the Enable Network Adapter checkbox. This will insert a default adapter including the type, connection, MAC address and cable. You will need to run through these selecting the values you need for your use case before the machine boots.

Depending on the network mode that you want, you can select one of the options (see Networking Modes) from the drop-list labelled Attached to.

Under Advanced options, you may also change the Adapter Type (the hardware in emulation), the Promiscuous Mode policy, MAC address and Cable Connected settings.

With the exception of the Cable Connected option, you cannot apply changes to network settings while a virtual machine is in the running state. Virtual machines go through their emulated BIOS routines on start up, registering the presence and configuration of their virtual hardware. The VirtualBox Manager does not allow you to change the hardware on the fly. You will have to shut down and restart a virtual machine for changes to emulated hardware settings to take effect.

The default network card (Adapter 1) is normally used to connect the Guest machines to the Internet using NAT via the Host machine. However, it is good practice always to set the first adapter to communicate with the Host and the second adapter to connect to the Internet.

The tabbed interface may be economical with on-screen real estate, but it is easy to forget about the adapter settings in tabs you can’t see when you are testing multiple adapters in one virtual machine.

Comments