One of the areas less understood by people learning to use virtualization software such as VMware, VirtualBox, etc., is that of virtualized networking. For example, how can you connect your guest OS to the Internet connection available on the host OS? In this article, we will discuss the various network types available for virtual machines and see how each type can be used.

VMware Training – Resources (Intense)

Note: The host OS is the physical machine on which you will install VMware, VirtualBox, etc. A guest OS is a virtual machine running in the virtualization software. This article assumes you have already installed a guest OS.

For this article, I have Oracle’s VirtualBox installed (it’s free!) but the concepts we will discuss here also apply to other software such as VMware Workstation. The VirtualBox is installed on my laptop (Windows 8 OS = host OS) and I also have several virtual machines in there but for this article, we will be using my Windows XP virtual machine (guest OS).

Generally speaking, there are three main virtual networking types/modes: NAT, Bridged and Host-Only. VirtualBox supports more such as Internal Network, Generic Driver, and so on, but we will restrict ourselves to the three main types.

Network Address Translation (NAT)

The NAT network type does exactly what you will expect it to do: the virtual machines are on a “private network” but can connect to the “external network” using the IP address of the host OS. The NAT device/engine usually sits between the virtual machine and the host and it translates packets from the virtual machine to the IP address of the host. It also listens for returning traffic so that it can send it to the required virtual machine. This means that the external network sees traffic from virtual machines as though it came from the host OS itself. When I use the term “external network,” I mean any network outside the guest OS, such as a LAN to which the host is connected, the Internet and so on.

Note: Technically speaking, this is more like PAT since all the virtual machines connect to the outside using one IP address – the host OS’s IP address.

As with normal NAT (dynamic NAT or PAT), the external network is unaware of the private network and as such, cannot initiate connection to the virtual machines. This provides a level of protection since virtual machines are hidden from the external network. However, it is possible to set up port forwarding to allow the outside world to connect to the guest OS on certain services.

In VirtualBox, you can set up NAT by selecting the virtual machine, navigating to Settings à Network à Adapter# à Attached to and then choosing NAT from the dropdown.

There is a virtual DHCP server responsible for assigning IP addresses to form the private network. In VirtualBox, the default private network subnet begins with 10.0.2.0/24, so if I check my Windows XP guest now, I should see an IP address in that range.

With this NAT configuration, the guest OS can also browse the Internet as shown below:

You should be aware that there are some limitations associated with the NAT network type, including performance issues and the fact that it may not support other protocols except TCP and UDP.

Bridged

The bridged networking type allows the guest OS to be seen as a unique entity on the network to which the host is connected to. For example, if you bridge the virtual network adapter of the virtual machine to the Wireless interface of the host, then the virtual machine will need an IP address on the Wireless network and be seen as part of that network separate from the host.

This is one of my most used virtual networking modes because I can connect to the guest OS uniquely on its own IP address. To set up bridged networking mode in VirtualBox, you select the virtual machine, navigate to Settings à Network à Adapter# à Attached to and then select Bridged Adapter. You then need to select which interface on the host (e.g. LAN, Wireless) that you want the virtual machine to be a part of.

In my case, I have made the virtual machine part of my wireless network. The host system is connected to the Internet via my home wireless router and the virtual machine should also be able to connect (on a separate IP address) to this router. The IP address configuration of my host system is as shown below:

Going back to the virtual machine, I see that it has been assigned an IP address of 192.168.1.6 which is different from the one used by the host OS.

With this configuration, the guest OS can also connect to the Internet:

Host-only

The third networking type we will be discussing is Host-only. The name is self-explanatory: it creates a network between the virtual machine and the host alone.

By default, the virtual machine can only communicate with the host and other virtual machines that are using the host-only networking mode. However, I will show you a way by which we can make the virtual machines connect to the Internet in this mode.

To configure Host-only mode in VirtualBox, you select the virtual machine, navigate to Settings à Network à Adapter# à Attached to and then select Host-only Adapter.

When you install VirtualBox, a software interface “VirtualBox Host-Only Ethernet Adapter” is created on your system and you can see/edit that interface just like your other network interface cards.

On the host system, the VirtualBox Host-Only Ethernet adapter is set to 192.168.56.1 while the virtual machine is assigned an IP address of 192.168.56.101 by the DHCP server (you can change the IP address subnet).

Like I said, by default, the virtual machines cannot connect to the Internet in Host-only mode. In fact, notice that the virtual machine does not have a default gateway in the above ipconfig output.

One way to go around this is to share your Internet connection with the VirtualBox Host-only adapter. In my case, the Internet connection on the host is through my wireless interface. To share your Internet connection in Windows, open Control Panel and go to Network and Sharing Center. On the left-hand pane, select Change adapter settings.

Right-click on the interface you want to share the connection FROM (i.e. the one that is connected to the Internet) and select Properties.

In the Properties dialog box that opens, select the Sharing tab and check the “Allow other network users to connect through this computer’s Internet connection” checkbox. Then select the interface you want to share TO, i.e. the VirtualBox Host-Only Ethernet adapter.

Depending on what OS you are using, when you share your Internet connection, the IP configuration of the interface you are sharing to is changed. In my case, it was changed from 192.168.56.1 to 192.168.137.1.

It’s either you change it back to what it was before, or you change the configuration on the virtual machine. We still have some configuration to do on the guest OS, so I will leave this at 192.168.137.1 and make the change on the guest OS.

To complete the setup, you will need to edit the IP configuration on the guest OS to use the host’s IP address as the default gateway and DNS server (or you can use a publicly available DNS server like 8.8.8.8).

Now we can confirm that the guest OS has access to the Internet by pinging google.com as we have done before.

Summary

In this article, we looked at the three main networking types available in most virtualization software including NAT, Bridged and Host-only.

In the NAT configuration, virtual machines connect to the external network by using the IP address of the host OS. The virtual machines can communicate among themselves using the private network but the outside world cannot connect to the virtual machines except when port forwarding is set up.

In the bridged configuration, virtual machines are unique systems on the network, separate from the host OS. As such, other systems on the network can communicate with the virtual machine as with any normal system.

In the Host-only networking mode, a private network is set up between the virtual machine and the host. By default, the virtual machines can only communicate among themselves and with the host, but with Internet connection sharing, they can be made to connect to the Internet.

I hope you have found this article insightful.

Further reading and References