VirtualBox and VMware default to NAT network type for virtual machines. You will be required to change the network type or forward ports if you are planning to run server software inside your VMs as they are isolated from incoming connections by default. In this post, we will see how you can forward ports to a virtual machine to use it like a server.
Forward Ports to a Virtual Machine to use it like a server
In order to forward ports to a Virtual Machine, you need to follow the methods mentioned below.
- Select a bridged network
- Using NAT Network mode
Let us talk about them in detail.
VirtuaBox Port forwarding
1] Select a bridged network
When you choose the NAT network type, your host operating system will perform network address translation. This means that the virtual machine will share your host computer’s IP address and won’t receive any incoming traffic. However, if you prefer your virtual machine to have its IP address and appear as a separate device on your network, you can use bridged networking mode instead.
Before we go ahead and make any changes to the network settings, shutting down the machines first is recommended.
In order to change a virtual machine’s network type in VirtualBox, you need to follow the steps mentioned below.
- Open VirtualBox.
- Right-click on the VM you want to mortify into a server and then select Settings.
- Now, go to the Network tab and select “Bridged Adapter” from the Attached to section.
- Click on Ok.
To change a virtual machine’s network type in VMWare, follow the steps mentioned below.
- Open VMWare Workstation.
- Right-click on the VM in question and select Virtual Machine Settings.
- Go to Network Adapter and then select “Bridged: Connected directly to the physical network”.
- Finally, click on Ok to confirm the changes you made.
This way, we have changed the network settings of your VM.
2] Using NAT Network mode
If you have opted to use NAT network mode for any reason, you can still forward ports through the virtual machine’s NAT. However, it is important to note that only one of these steps is necessary. You do not have to forward ports if you have already enabled bridged networking above.
Earlier, we needed to use the VBoxManage command to forward ports in VirtualBox, but now VirtualBox has a simple graphical port-forwarding window. Nevertheless, if you prefer to set up port forwarding with the VBoxManage command instead of the graphical interface, go to virtualbox.org to find the correct instructions as we will be using the GUI in this guide.
To forward ports in VirtualBox using GUI, follow the steps mentioned below.
- Open VirtualBox, right-click on your VM, and click on Settings.
- Go to the Network tab, in the Attached to option, select NAT, and click on Advanced.
- Next, click on Port Forwarding.
- Click on the Add icon to add a port.
- To forward ports in VirtualBox, use the Port Forwarding Rules window. You can leave the IP fields blank to accept all traffic from the local network and forward it to your virtual machine. Since we don’t want that, use the Host IP address – 127.0.0.1.
- Finally, save the changes and close the window.
That’s how you can do port forwarding in VirtualBox.
If you are using VMware, you will need to use the Virtual Network Editor (vmnetcfg) application to perform certain tasks. If you are a VMware Workstation user, you can navigate to Edit and then Virtual Network Editor to access it.
Do keep in mind that this utility is not available for VMware Player. However, you can still use bridged networking mode to make your server accessible. Although there are methods to install it manually by extracting the vmnetcfg.exe file from the VMware Player installer.
Your VM is still not ready to be used as a server, you need to make sure that there is no security program running in your virtual machine or host that can potentially block the connection, add an exception if that exists. Also, ensure that the router is forwarding the port correctly.
That’s it!
Read: How to configure & set up Router Firewall settings
How to forward ports to a virtual machine and use it as a server?
With the help of NAT or Network Address Translation, we will be able to forward ports to a virtual machine. You can follow the steps mentioned earlier in this post to learn how to do the same and use Bridged Network.
Read: How to create a public VPN Server on Windows?
Is port forwarding the same as virtual server?
Port Forwarding and Virtual Servers are similar but not the same. The primary difference between the two is that “Virtual Servers” can only forward a single port and change its number, while “Port Forwarding” can forward whole ranges but cannot change the port number.
Also Read: How to change NAT type on PC.