Forward Ports to Virtual Machine: Turn it into a Server

Networking Virtual Machines: NAT, Port Forwarding, and Accessibility
Both VirtualBox and VMware utilize Network Address Translation (NAT) as the default networking configuration for newly created virtual machines.
This default setting is generally sufficient for typical virtual machine usage scenarios.
Why NAT is the Default
Virtual machines are not always required to be directly accessible from the external network. Consequently, NAT provides a sensible default configuration.
Employing NAT inherently enhances security by shielding the virtual machine from unsolicited incoming connections.
Running Server Software
If the intention is to operate server applications within a virtual machine environment, adjustments to the network configuration are necessary.
This can be achieved either by modifying the virtual machine’s network type or by implementing port forwarding through the existing NAT network.
Understanding the Implications
The default NAT configuration effectively isolates the virtual machine, preventing direct access from outside the host system.
For most users, this isolation is beneficial, contributing to a more secure computing environment.
However, when hosting services, this isolation must be overcome to allow external clients to connect.
Utilizing Bridged Networking
When employing the NAT network configuration, your host system manages network address translation. Consequently, the virtual machine utilizes the host computer’s IP address and is unable to accept direct incoming connections. An alternative approach is to implement bridged networking.
In bridged mode, the virtual machine functions as an independent device on your network, acquiring its own unique IP address. This allows for direct communication with other devices on the network.
To modify a virtual machine’s network type within VirtualBox, initiate the process by right-clicking the desired virtual machine and selecting “Settings”. If the “Settings” option is unavailable, ensure the virtual machine is powered off before proceeding with the changes.

Within the Network settings, choose the “Bridged Adapter” network mode and confirm your selection by clicking “OK”. Further details regarding each networking mode are available in the “Introduction to networking modes” section of the VirtualBox user manual.

A comparable procedure applies to VMware applications. Begin by right-clicking a virtual machine that is powered off and selecting “Virtual Machine Settings”.

Next, select the “Network Adapter” virtual hardware component. Then, choose the “Bridged” network connection type and finalize the changes by clicking “OK”.

Port Forwarding to a Virtual Machine
Employing Network Address Translation (NAT) network mode offers an alternative method for forwarding ports within your virtual machine’s network configuration. It’s important to understand that implementing either bridged networking or port forwarding is sufficient; performing both isn’t required.
Historically, port forwarding in VirtualBox necessitated the use of the VBoxManage command-line tool. However, VirtualBox now features a user-friendly graphical interface for this purpose. Should command-line configuration be preferred, detailed instructions can be found within the VirtualBox documentation.
To initiate port forwarding within VirtualBox, begin by accessing the virtual machine’s settings. This is achieved by selecting the "Settings" option from the main menu.

Within the virtual machine’s configuration window, navigate to the "Network" pane. Expand the "Advanced" section, and then click the "Port Forwarding" button. This button becomes active only when a NAT network type is selected, indicating the necessity for port forwarding.

The VirtualBox Port Forwarding Rules window allows you to define the port forwarding rules. Specifying IP addresses is optional in this configuration.
It’s worth noting that leaving the "Host IP" field blank instructs VirtualBox to listen on all available interfaces (0.0.0.0), accepting traffic from the entire local network and directing it to the virtual machine. Conversely, entering 127.0.0.1 into the "Host IP" field restricts access to traffic originating solely from the host operating system.

For VMware users, the Virtual Network Editor (vmnetcfg) application is required to configure port forwarding. This application can be accessed through the "Edit" menu, then selecting "Virtual Network Editor" within VMware Workstation.
However, the Virtual Network Editor is not included with VMware Player. While it was previously possible to extract the vmnetcfg.exe file from the VMware Player installer, it appears to have been removed from recent versions, such as VMware Player 5.0. If you are using VMware Player, utilizing bridged networking remains a viable option for server accessibility.
Successfully making server software within a virtual machine accessible requires more than just port forwarding. Ensure the following conditions are met:
- The firewall software operating within the virtual machine does not impede incoming connections. This may involve explicitly allowing the server program through the guest operating system’s firewall.
- The firewall on the host computer isn’t blocking connections, particularly when using NAT mode with port forwarding. Bridged networking bypasses the host computer’s firewall.
- Your network router is correctly configured to forward the necessary ports, if external access from the Internet is desired. (Refer to our router port forwarding guide for assistance.)