Ubuntu – Port forwarding to virtual machine

port-forwardingUbuntuvirtualbox

I'm running an http(zope) server on Ubuntu 8.04 server, in a Virtualbox machine, on an Ubuntu 9.04 box. The guest system accesses network over NAT. How can I forward the host machine's port 80 to the guest system's http port?

Best Answer

You have to enable port forwarding in VirtualBox. You can do that by using the VBoxManage command. For example:

VBoxManage setextradata VM_NAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/HostPort" 8888
VBoxManage setextradata VM_NAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/GuestPort" 80
VBoxManage setextradata VM_NAME "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guesthttp/Protocol" TCP

In this case, this will open port 8888/tcp on your host (physical machine), and forward it to port 80/tcp of your virtual machine (replace VM_NAME with the name of your virtual machine).

For more details, see "Configuring port forwarding with NAT" in the VirtualBox User Manual (section 6.4.1, p. 84)

If you need external access to the web server hosted on your virtual machine, then you'd also need to create a port forwarding rule (for example through iptables or configuring it in your router).