Portforwarding with VirtualBox with NAT networking

VirtualBox with NAT networking works by sending data from your virtual machine to the VirtualBox NAT engine witch in turn sends data to the internet through the hosts network connection. Your virtual machine will get an ip witch won’t be on the same subnet as your host machine, so you can’t reach it without setting up port forwarding.

For example, to set up SSH with a linux guest OS, we need to open Cmd and navigate to the VirtualBox directory. Here we need to run this command. Replace VM name with the name of your virtual machine.
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage is the executable file running the command, modifyvm is a parameter passed to VBoxManage to tell it what to do. –natpf1 explains witch network interface on the guest machine we will be connecting on, guestssh is just the name of the rule.

This would probably look something like this:

After you’ve run this command, you can effectively connect to localhost on port 22 with an ssh client.

The same procedure would be used to e.g. set up a webserver. You would probably use port 80 for this, and it should look something like:
VBoxManage modifyvm "VM name" --natpf1 "guestweb,tcp,,80,,80"

Be the first to comment

Leave a Reply