As you might know virtualbox is type 2 hypervisor. It helps in virtualizing different operating systems on the top of our computer. It is a great way by which you can leverage different operating systems, without buying / maintaining extra hardware.
And if you have already tried installing different OSes in it. You might also be familiar with different networking modes it gives you. Probably by default you have NAT selected .
Networking settings in VirtualBox
Click on Network and you will see 4 different network adapters there (There are actually 8 but you can configure only 4 with the GUI). Among which only 1 is enabled having NAT configured by default, in the Attached to dropdown. There you will also see 8 different modes you can select. Which are –
- Bridge Adapter
- Internal Network
- Host-Only Adapter
- Generic Adapter
- NAT network
- Cloud Network [EXPERIMENTAL]
- Not Attached
Among these the last 3 are not very common, so we won’t be talking about them right now.
You will also see an Advances dropdown. Where you will see the different adapter types that are supported and can be virtualized for each setting.
NAT stands for network address translation. It does what NAT actually does. It shields the devices behind a router, and to connect to devices outside the router, their private ip is changed into the host ip. In the context of virtualbox, this device is the VM and the router is your host machine.
But the NAT setting creates 1 separate network for each VM. This means VMs can’t talk to each other. Also Host and devices in it’s LAN cannot talk to the VM directly.
This is the default virtuabox network setting, and is sufficient if you just want a computer which can connect to the internet.
As we just discussed, NAT creates separated network for each VM, therefore different VMs cannot talk to each other. This is where NAT network comes into play. Actually its very similar to NAT, but instead of making separate networks for each VM, you can created different networks which can have multiple VMs. Hence it allows communication between VMs (if they are at the same NAT network).
As of version 6.1.38, you can create these networks in File < Preferences < Networks.
By default you will have a NatNetwork_1 created for you.
A bridge adapter basically creates a bridge network. Bridge network is a network where 2 LANs connect to each other to make another single LAN. In this way, Bridge network basically makes it easy for devices in 2 different networks to connect to each other.
Here virtualbox uses the ‘net filter’ driver on your host, which allows your VM / bridge adapter to directly communicate to devices in the home network. In simpler words, it allows your VM to appear as a device on the LAN your host is actually in.
While enabling a bridge adapter in one of the VMs for the first time, you might get a warning from windows firewall. It will ask you if you really want to enable this, and that’s obvious since you are creating a whole new different device which can participate in all the activities in a real world LAN. So you should simply give it all the permissions it need in order to make this bridge network successful.
This mode can be used to create different virtualbox LANs / networks where multiple VMs can talk to each other internally. But the host machine is not a part of this network.
By default, the internal network is named as ‘intnet‘. You can create more by simply typing it at the name option
A host only allows you to create an internal network with the host being part of it. By default you will have 1 host-only adapter installed in your host device. You can create more in File < Host Network Manager. You can also assign an IP range to it.
Here’s an advice – Never delete all the host only adapters from virtualbox. You should always have at least one host only adapter installed. Because if you do uninstall all these adapters, to make new one, you will have to install virtualbox again.
Port forwarding is a well know concept in networking. It basically allows devices outside a NAT configured LAN to communicate with devices inside. They do this by first assigning different ports in the router for a specific port of different devices in the LAN.
This way if one device outside this network wants to communicate to one the devices inside, it needs the router’s IP along with the port assigned by the router for that device.
You can configure port forwarding in Virtualbox NAT and NAT network modes.
- Since NAT comprises of only 1 VM, you can simple go to the network adapter setting of a specific VM, and click on port forwarding.
- Add a port forwarding rule.
- Name it
- Select a protocol (TCP OR UDP)
- Leave the host ip blank if you want that any device can connect to your VM.
- Select the port of the host you want to use. (Make sure no other VM is using the same)
- Leave the guest ip blank
- Select the guest port.
For NAT network
- Go to Preferences.
- Select network
- click on the properties of the the network.
- Configure port forwarding like we did in NAT.
Here is a table showing which virtualbox networking mode can do what.
We have talked about how you can configure different networking setting in virtualbox for your VMs. These settings can be used for your own projects or preference. The way these modes are configured are very similar in other hypervisors like vmware too.
There is even more networking settings you can play with. But for that you would need to use the CLI( command line interface). Yes everything is limited with the GUI .