First thing to do is shut the virtual machine down. And power the virtual machine off.
Start a command prompt as administrator. Click Start menu and then type cmd in the search programs and files box. The system will come up with cmd.exe. Right click on this and select run as administrator.
Next type the following commands:
cd "c:\Program Files\Oracle\VirtualBox" VBoxManage modifyvm "ubuntu01" --natpf1 "guestssh,tcp,,2222,,22" VBoxManage modifyvm "ubuntu01" --natpf1 "guestwww,tcp,,8888,,80"
where ubuntu01 is the virtualmachine name. guestssh and guestwww are the portforward rule names. On this names we can alter to delete the rules if we want. The next value is the protocol, in our case tcp. Next value is empty. This is the ip address to bind on the host. If empty is will bind to all addresses. The next one (2222 and 8888) is the host port to bind on. Next the ip address on the guest to bind. Leave this empty. Next is the port to bind on. 22 for ssh and 80 for web.
Let’s try it out with putty (the best ssh client for windows).
First fire up your virtual machine (ubuntu01). You will get a firewall warning from windows. Click accept to accept this. When you see the login prompt of ubuntu01 we can start putty and make a connection to 127.0.0.1:2222
And there we have a connection
There is also a way to remove the port forwarding rules. First thing is to shut the virtual machine down and power it down.
Start the Command Prompt as administrator and run the following commands:
cd "c:\Program Files\Oracle\VirtualBox" VBoxManage modifyvm "ubuntu01" –natpf1 delete "guestssh" VBoxManage modifyvm "ubuntu01" –natpf1 delete "guestwww"