If you’re looking to turn your old laptop or desktop into a server, one of the first things you’ll need to do is open up the ports. This can be a bit of a challenge if you’re using a virtual machine, as most virtual machines don’t allow you to forward ports. Fortunately, there’s an easy workaround: You can use your virtual machine as a server by forwarding the appropriate ports through the host computer. Here’s how to do it:
- Open up the virtual machine’s settings and click on “Network.”
- Under “Adapter 1,” click on “Port Forwarding.”
- In the “Port Forwarding” window, click on “Add New Port Forwarding Rule.”
- In the “Port Number” field, type in the port number that you want to forward (for example, 80). In the “Protocol” field, select TCP from the drop-down menu. In the “Destination Address” field, type in your computer’s IP address (for example, 192.168.1.100). In the “Source Address” field, type in your computer’s IP address (for example, 192.168.1.101). Click on OK to add the port forwarding rule.
- Repeat these steps for each port that you want to forward (for example, 443 for HTTP and 8080 for HTTPS). Once all of your port forwarding rules have been added, click on OK to save them and close out of the virtual machine’s settings window. ..
VirtualBox and VMware both create virtual machines with the NAT network type by default. If you want to run server software inside a virtual machine, you’ll need to change its network type or forward ports through the virtual NAT.
Virtual machines don’t normally need to be reachable from outside the virtual machine, so the default is fine for most people. It actually provides some security, as it isolates the virtual machine from incoming connections.
Selecting Bridged Networking
With the NAT network type, your host operating system performs network address translation. The virtual machine shares your host computer’s IP address and won’t receive any incoming traffic. You can use bridged networking mode instead — in bridged mode, the virtual machine will appear as a separate device on your network and have its own IP address.
To change a virtual machine’s network type in VirtualBox, right-click a virtual machine and select Settings. If you can’t click Settings, you’ll need to power off the virtual machine before making these change.
Select the Bridged adapter network mode in the Network settings section and click OK. For more information about each type of network mode, consult the Introduction to networking modes section in VirtualBox’s manual.
The process is similar in VMware applications. First, right-click a powered off virtual machine and select Virtual Machine Settings.
Select the Network Adapter virtual hardware device, select the Bridged network connection type, and click OK.
Forwarding Ports to a Virtual Machine
If you prefer to use NAT network mode for some reason, you can also forward ports through the virtual machine’s NAT. Note that only one of these steps is necessary – you don’t have to forward ports if you enabled bridged networking above.
At one point, you had to use the VBoxManage command to forward ports in VirtualBox, but VirtualBox now contains a simple graphical port-forwarding window. If you need to set up port forwarding with the VBoxManage command instead of using the graphical interface, you’ll find instructions for doing so in VirtualBox’s manual.
To forward ports in VirtualBox, first open a virtual machine’s settings window by selecting the Settings option in the menu.
Select the Network pane in the virtual machine’s configuration window, expand the Advanced section, and click the Port Forwarding button. Note that this button is only active if you’re using a NAT network type – you only need to forward ports if you’re using a NAT.
Use VirtualBox’s Port Forwarding Rules window to forward ports. You don’t have to specify any IP addresses – those two fields are optional.
Note: While you don’t have to enter any IP details, leaving the Host IP box blank will make VirtualBox listen on 0.0.0.0—in other words, it will accept all traffic from the local network and forward it to your virtual machine. Enter 127.0.0.1 in the Host IP box and VirtualBox will only accept traffic originating on your computer—in other words, on the host operating system.
If you’re using VMware, you’ll need to use the Virtual Network Editor (vmnetcfg) application to do this. VMware Workstation users can select Edit –> Virtual Network Editor to open it.
Unfortunately, this utility is not included with VMware Player. There are methods for installing it yourself by extracting the vmnetcfg.exe file from the VMware Player installer, but I couldn’t locate the vmnetcfg.exe utility in the latest version of VMware Player, VMware Player 5.0 – it may no longer be included in the installer. If you’re using VMware Player, you can still use bridged networking mode to make your server accessible.
Remember that this is only part of the process of making the server software inside a virtual machine reachable. You’ll also need to ensure that:
The firewall software running inside your virtual machine isn’t blocking the connections. (You may need to allow the server program in the guest operating system’s firewall. ) The firewall software on your host computer isn’t blocking the connections. (This only applies to NAT mode with port forwarding – the host computer’s firewall doesn’t interfere in bridged networking mode. ) Your router is forwarding ports correctly – this is only necessary if you want to access the virtual machine from the Internet. (Consult our guide to forwarding ports on routers here. )