Sunday, June 17, 2012

VirtualBox: Access NAT-Virtual Server from Host

If you want to set-up a virtual development server on a laptop, so you can work anywhere, you need to select NAT for your network setting on your guest. Doing so, you can't connect from your host to the Virtual server (guest) without using Port forwarding.

Example: We want the following connections from our host to the guest;  ssh, http, https on the ports 22, 80, 443. I don't like to use the default ports for these services on my host, therefore, I forward from a different port: ex. HTTP, Host (2080)  to Guest (80)


Two ways to set this up:
1. Via command line:
You need to know the name you gave to your Guest, in my case: "Development Server" Substitute this by your own server name. The virtual machine can not be running while you type the following commands at the prompt:

SERVER_NAME="Development Server"
VBoxManage modifyvm "$SERVER_NAME" --natpf1 "guestssh,tcp,,2022,,22"
VBoxManage modifyvm "$SERVER_NAME" --natpf1 "guesthttp,tcp,,2080,,80"
VBoxManage modifyvm "$SERVER_NAME" --natpf1 "guesthttps,tcp,,2443,,443"

2. VirtualBox software:
Select in the network setup NAT, and open the advanced drop-down, and click on the button "Port Forwarding: 
Here, you define the ports you want.







The next time you start your guest, the ports are forwarded.
On your Host you can reach the http service of your guest with localhost:2080


No comments:

Post a Comment

Please be courteous, even if you do not share the same view.