Thursday, March 15, 2012

Enable portforwarding ssh and web traffic to Virtualbox Ubuntu Server

Thursday, March 15, 2012 Posted by Andre Broers , , , , 8 comments
In a previous post I explained how to install ubuntu server in a virtualbox vm and cloned the ubuntu to an ubuntu01 image in this post. In the following post I will explain how to enable port forwarding to this new server so you can login to the server with putty or other client (and copy and paste will work better) and you can test some webapplications running on your new server.
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"



8 comments:

  1. After read the discussion which is very essential for me as well. I must follow the content which is very essential for me as well. I must follow the discussion which is very essential for me as well. Keep it up.
    customer recovery

    ReplyDelete