Blog Post

VirtualBox Multiple TCP Port Forwarding

When I need to test some Django code, I find it much easier to just run or install a copy of Turnkey Linux and grab the appliance that I need. They have a few different types of appliances and if you need to do any code testing for Django, Rails, Drupal, and more, I suggest you give this a shot if you don’t want to sit there and configure a server just for testing.

One thing with the Turnkey Django appliance, there are 2 HTTP ports. One is 80 for the Django administration interface and the other is 10000 for the Webmin administration interface. One problem I just ran across was how do I forward 2 TCP ports with Virtual Box. Easy, just do this:

$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 8888
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP

To connect to your guest OS via Firefox, you would go to the following URL in your web browser: http://localhost:8888

This works great for one port, but what if I need 2 HTTP ports? Then try this:

$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort" 8889
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort" 10000
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol" TCP

To connect to your guest OS via Firefox to this port, look above on how I explained the connection via port 8888. Just change the 8888 to 8889.
Adding more than this, well that I will have to dig in to further, but for this case, I only needed to forward the 2 HTTP/Apache ports.

Now if you would like to SSH into your guest, try this:

$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
$ VBoxManage setextradata <vbox guest name> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

You can now SSH into your guest box by typing the following at the command line:

$ ssh -p2222 username@localhost

Or you could add the following to your ~/.ssh/config:

Host guest
        Hostname localhost
        Port 2222
        User username

And now to connect you would just do:

$ ssh guest
This entry was posted in Application and tagged , , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.
  • Archives

semidetached
semidetached
semidetached
semidetached