How to Network Virtual Machines in VirtualBox

Instructor: Muhammad Wannous

Muhammad has been teaching Computer Sci. and Eng. and has a Ph.D. degree in Computer Sci. and Electrical Eng.

Virtual Machines (VMs) run isolated from each other on one large host. However, as conventional computers communicate over a network, VMs can also be connected in different ways. In this lesson, we will study some of the networking scenarios available for creating a network of VMs and apply one of them in practice.

Networking Virtual Machines

A Virtual Machine (VM) is a combination of many virtual resources and among them is one or more virtual network interfaces. The hypervisor or Virtual Machine Manager (VMM), which is the software layer responsible for managing VMs, prepares these network interfaces and make them appear to the guest operating system, which runs inside the VM, as conventional Network Interface Cards (NICs) with MAC addresses assigned on creation.

Constructing a network requires devices other than the NICs such as switches, routers, Dynamic Host Configuration Protocol (DHCP) server, etc. In the virtualized environment the VMM has virtual network devices that simulate the physical ones. Some of these virtual network devices are:

  • Virtual switch
  • Bridge
  • Virtual Host Adapter
  • Network Address Translation (NAT) device
  • DHCP server

The VMM uses these virtual network devices in different combinations to allow scenarios where VMs connect with each other and with the external network the host machine has access to. The most popular three networking plots of VMs are:

  1. NAT networking
  2. Host-only networking
  3. Bridged networking

Table-1 provides a quick overview of these networking scenarios.

Table-1: An overview of networking modes

VM↔Host VM↔VM VM→External network External network→VM VM's IP Visiblity to the External Network
NAT No No Yes Yes(Port forwarding) Hidden
Host-only Yes Yes No No Hidden
Bridged Yes Yes Yes Yes Visible

NAT - Network Address Translation

In this mode, the VMM creates a connection between the virtual network interface of the VM and a NAT device which is in turn connected to a DHCP server as demonstrated in Figure-1.


Figure-1: Network Address Translation (NAT) Networking
Network Address Translation (NAT) Networking


The VM obtains a private IP address from the DHCP server upon starting up, and the VMM maps this address to a TCP port number on the host machine. Traffic originated from the VM will be seen on the external network as if it was coming from the host machine's IP address, not the VM's. The NAT mode permits access to a VM from the external network by implementing the port forwarding feature.

Host-only Networking

This mode is useful when the user wishes to connect a set of VMs, in addition to the host platform, to an isolated network. In this scenario, the VMM creates a virtual host adapter that acts as a NIC within the host machine and connects it, in addition to the other VMs, to a virtual switch as shown in Figure-2.


Figure-2: Host-only Networking
Host-only Networking


The user may let the machines in the host-only network to obtain their configurations from an optional DHCP server that can be attached to the network or configure them manually. The VMs in this scenario neither appear on the external network, nor can they access it.

Bridged Networking

This scenario provides a solution that allows VMs to be exposed to the external network the host machine connects to, as illustrated in Figure-3. The VM will appear as an individual platform on the external network and get its configuration in the same way the host machine does.


Figure-3: Bridged Networking
Bridged Networking


Networking in Practice

Let's try to practice networking in one of the widely used VMMs, Oracle VirtualBox. We will be considering an isolated network comprising two VMs (VM-1 and VM-2) as illustrated in Figure-4. Each of the two VMs has one ''Ethernet'' connection, and they obtain their configurations from a DHCP server.


Figure-4: Practice Network
Practice Network


We start from the point where the two VMs are ready in VirtualBox (as in Figure-5) and complete the following steps:

  1. Create a host-only network (switch) with DHCP enabled.
  2. Verify that both VMs have a virtual network interface and attach it to the host-only switch.
  3. Start the two VMs and verify their IP addresses
  4. Test the connectivity by using the ''ping'' command on each VM.


Figure-5: The Two VMs in VirtualBox
The Two VMs in VirtualBox


The guest operating system of our VMs is Ubuntu 16.04.5 LTS, and VirtualBox version is 5.2.18 r124319 (Qt5.6.2).

Creating a Host-only Network (switch) with DHCP Enabled

  • Select the ''File'' menu → ''Host Network Manager''
  • In the new window, select the ''Network'' menu → ''create''. In this way, we direct VirtualBox to construct a new virtual switch (host-only network).
    • This process might trigger a system change alert, so go ahead and continue.
    • If this is the first host-only adapter you create in VirtualBox then its name should be similar to ''VirtualBox Host-Only Ethernet Adapter''.
  • Select the adapter you have just created → select the ''Network'' menu → ''Properties''
    • The adapter properties appear at the bottom of the current window as shown in Figure-6.


Figure-6: VirtualBox Host Network Manager
VirtualBox Host Network Manager


To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support