How to configure VirtualBox network options for VMs

The popular VirtualBox program for creating virtual machines for operating systems has a large number of configuration options at the network level. These options allow us to define if a virtual machine has to have access to the Internet and access to the local home network, or if, on the contrary, we want to isolate the network traffic of that virtual machine in question so that it does not have communication with other computers. the local network and only with the real computer. Today in this article we are going to explain all the configuration modes at the network level that we can carry out with VirtualBox, so that you learn when it is better to choose one option or another.

configure VirtualBox network options for VMs

Network Options Available in a Virtual Machine

The popular free program to create virtual machines allows us to add up to a total of four different network adapters to the same virtual machine. In addition, it will allow us to enable or disable these network adapters easily and quickly, in case we want to leave the virtual machine that we are running without a network connection. If we go into the configuration of any virtual machine, we will be able to see all the options that we have available:

  • NAT
  • bridge adapter
  • Internal network
  • Host-only adapter
  • generic driver
  • NAT network
  • Cloud network
  • Not connected

In the following image you can see all the configuration options that we can currently perform. The default option when we create a virtual machine is “NAT”, as you can see:

Now that we know the main configurations at the network level that we can carry out in a virtual machine with VirtualBox, we are going to explain in detail how each of these options works.

NAT

This configuration mode is the default on all VirtualBox virtual machines. In this configuration mode, the VM will obtain a private IP address from a subnet defined by VirtualBox itself. When we are in a NAT configuration, the virtual machine will go out to the local home network and to the Internet using the private IP address of the real computer, therefore, it is as if the real computer were exchanging traffic, since NAT is done on the address Real private IP of the computer in question.

In this configuration mode, the virtual machine can communicate with any computer on the home or professional local network that the real PC can reach, it can also have Internet connectivity if the real PC has connectivity. If a computer on the local network wants to communicate with the virtual machine that is running, it will not be able to do so directly because we are working in a NAT scenario.

If we want to mount a network service in the VM such as an SSH or FTP server among others, we must click on the “Port Forwarding” option, this option is found in the “Network” section when we select the type of network to NAT . It is absolutely necessary to forward TCP and/or UDP ports to be able to establish communication from “outside” (local network) to “inside” (virtual machine), and even if you want to communicate, the host itself must do a port forwarding. ports.

bridge adapter

In this configuration mode, the virtual machine becomes one more computer within the home or professional local network. Using the physical network adapter of the real computer, we will connect the VM to the local network with its corresponding MAC address, or it will obtain an IP address from the DHCP server that we have on the local network, and not from the VirtualBox DHCP server.

In this operating mode, the virtual machine will have communication with the rest of the computers on the local network and with the Internet, in addition, the rest of the computers will also be able to communicate with the virtual machine without problems, since we are not in a NAT environment like The one before. Now the VM will be one more computer within the local network with its corresponding MAC, private IP address, etc.

This configuration mode is ideal if we want to make the virtual machine pass for another computer within the local network, and we want other computers to also have direct communication with the virtual machine, without the need to do port forwarding or anything.

Internal network

This configuration mode allows us to create a local network of two or more virtual machines, where two or more VMs that we have configured can communicate with each other without problems. In this configuration mode, the virtual machines will not have access to the local home or professional network, nor will they have access to the Internet. In this mode of operation, what is done is to create a virtual network where only the selected VMs can communicate with each other.

If you are going to do a lab with several virtual machines and you want them to have network communication only between them, but not be able to communicate with us or with the local network or the Internet, this is the configuration mode that you should apply. Finally, VirtualBox allows us to create several internal networks, to have different VMs contained in them and configure the communication in an advanced way.

Host-only adapter

In this communication mode, the network adapter only has connectivity with the host computer, that is, with the real computer that is running VirtualBox with the virtual machine. This virtual machine is totally isolated from the other machines on the local network where the host is connected, in this way, we can protect the local network against a possible VM that is infected with some malware, although logically we must be very careful ourselves. that with our PC we will have communication.

This configuration mode is ideal if we want to communicate with the VM over the network, but we do not want said virtual machine to have access to our local network or the Internet, simply two-way communication between the real and virtual machine.

generic driver

In this configuration mode, VirtualBox allows you to choose a network driver that is distributed to all virtual machines. In all the configuration options except this one, what VirtualBox does is virtualize specific models of network cards, however, in this mode we will have to provide the drivers.

This mode of operation is not usually used, in fact, in all configuration modes we have the type of adapter «virtio-net paravirtualized network» that allows us to abstract the network card from the real equipment and provide the maximum possible performance, although if If we choose this option, we will have to install the virtio drivers in the virtualized machine, otherwise it will not work (it will not recognize the network card).

In this mode we can use UDP tunnels to interconnect virtual machines running on different hosts directly, easily and transparently through an existing network. You can also create a VDE (Virtual Distributed Ethernet) network to connect to an Ethernet switch on a Linux or FreeBSD host. These options are quite advanced and usually require extensive knowledge.

NAT network

In this configuration mode we have the possibility of creating a NAT network with the addressing that we want, we can also add a DHCP server to provide IPv4 addressing to all machines, and even supports IPv6 and port redirection.

In this configuration mode we have a kind of “Internal network + NAT”. In «RED NAT» we will have all the virtual machines in the same NAT subnet and they will be able to communicate with each other, because they all have the same addressing and VirtualBox allows this communication, in addition, they will also be able to communicate with the computers of the local home network and even go online.

To configure this «NAT Network» the first thing we must do is create a new one, and then apply this configuration in detail to each VM that we want.

Cloud network

This configuration mode is currently in the experimental phase, the goal is to be able to connect the VM directly to the Oracle Cloud to later add more VMs and have communication between them. If you do not know what the Oracle Cloud is and what options you have, surely this option is not what you are looking for.

In addition, there are other options that would also allow you to interconnect virtual machines in NAT, NAT network or bridge adapter mode, such as installing the ZeroTier software, which is an SDN VPN that allows us to quickly and easily interconnect devices.

Not connected

In this configuration mode, the virtual machine will have a network card installed, but it will not be connected to the VirtualBox, so it will not have access to any network, be it a local network, the Internet, nor will it have network communication with the real computer. This configuration mode is used to simply “isolate” the virtual machine and not have communication with anything, however, we could do this same behavior if we do not directly enable the VirtualBox network adapter, although in this case the card will not even appear. network in the operating system of the virtual machine.

In the following official VirtualBox table, you can see the different communication modes and if there is communication between the VM and the host, as well as between the VM and the local network to which we are connected, so that everything is clearer:

As you have seen, in VirtualBox we have a large number of options to allow or not the communication of virtual machines as we wish.