Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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).

share|improve this answer
    
For the detailed iptables rules, see this post: mydebian.blogdns.org/?p=111 –  Don Kirkby Jan 25 '10 at 18:41
add comment

figure out what ip address has the guest system (though it's dhcp assigned, it's more likely it will have the same address after reboot; if not, switch to static ip's)

iptables -t nat -A PREROUTING -s 0/0 -d IP_HOST -p tcp --dport 80 -j DNAT --to IP_GUEST:80
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.