As the virtual machine is connected to a private network internal to
To an application on the host or other physical or virtual machines on the network, it looks as though the service being proxied is actually running on the host. This also means that you cannot run the same service on the same ports on the host. However, you still gain the advantages of running the service in a virtual machine. For example, services on the host machine or on other virtual machines cannot be compromised or crashed by a vulnerability or a bug in the service, and the service can run in a different operating system than the host system.
To configure port forwarding you can use the graphical Port Forwarding editor which can be found in the Network settings dialog for network adaptors configured to use NAT. Here, you can map host ports to guest ports to allow network traffic to be routed to a specific port in the guest.
Alternatively, the command line tool
You will need to know which ports on the guest the service uses and to decide which ports to use on the host. You
may want to use the same ports on the guest and on the host. You can use any ports on the host which are not
already in use by a service. For example, to set up incoming NAT connections to an
VBoxManage modifyvm "VM name" --nat-pf1 "guestssh,tcp,,2222,,22"
In the above example, all TCP traffic arriving on port 2222 on any host interface will be forwarded to port 22 in
the guest. The protocol name
To remove this forwarding rule, use the following command:
VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"
If for some reason the guest uses a static assigned IP address not leased from the built-in DHCP server, it is required to specify the guest IP when registering the forwarding rule, as follows:
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,10.0.2.19,22"
This example is identical to the previous one, except that the NAT engine is being told that the guest can be found at the 10.0.2.19 address.
To forward all incoming traffic from a specific host interface to the guest, specify the IP of that host interface as follows:
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,127.0.0.1,2222,,22"
This example forwards all TCP traffic arriving on the localhost interface at 127.0.0.1 through port 2222 to port 22 in the guest.
It is possible to configure incoming NAT connections while the VM is running, see