I assume that this question is related to your previous question about VirtualBox.
Have your configured your Ubuntu web server to listen on the ethernet network interface (probably eth0) with the IP address of 10.0.2.15? If not, configure your web server to listen on the ethernet network interface. My guess is that your web server is only configured to listen on the loopback interface 127.0.0.1 — 127.0.0.1 is only accessible within your Ubuntu VM. ie it is not accessible from your Windows host.
As others mentioned in your previous question: configure VirtualBox to use bridged networking mode so that your VM becomes just another machine on your network. Bridged networking mode ends up being simpler and you won't have to bother with VirtualBox port forwarding. :-)
The latest stable release for libvirt for Ubuntu is version 0.7.5, which doesn't have some newer features (i.e. script hooks and network filters) which make automatic network configuration easier. That said, here's how to enable port forwarding for libvirt 0.7.5 on Ubuntu 10.04 Lucid Lynx.
These iptables rules should do the trick:
iptables -t nat -I PREROUTING -p tcp -d 1.2.3.4 --dport 80 -j DNAT --to-destination 10.0.0.1:80
iptables -t nat -I PREROUTING -p tcp -d 1.2.3.4 --dport 22 -j DNAT --to-destination 10.0.0.2:22
iptables -I FORWARD -m state -d 10.0.0.0/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT
The default KVM NAT config provides a rule similar to the 3rd I gave above, but it omits the NEW state, which is essential for accepting incoming connections.
If you write a startup script to add these rules and you're not careful, libvirt 0.7.5 overrides them by inserting its own. So, in order to make sure these rules are applied properly on startup, you need to make sure libvirt has initialized before you insert your rules.
Add the following lines to /etc/rc.local, before the line exit 0
:
(
# Make sure the libvirt has started and has initialized its network.
while [ `ps -e | grep -c libvirtd` -lt 1 ]; do
sleep 1
done
sleep 10
# Set up custom iptables rules.
iptables -t nat -I PREROUTING -p tcp -d 1.2.3.4 --dport 80 -j DNAT --to-destination 10.0.0.1:80
iptables -t nat -I PREROUTING -p tcp -d 1.2.3.4 --dport 22 -j DNAT --to-destination 10.0.0.2:22
iptables -I FORWARD -m state -d 10.0.0.0/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT
) &
The sleep 10
above is a hack to make sure the libvirt daemon has had a chance to initialize its iptables rules before we add our own. I can't wait until they release libvirt version 0.8.3 for Ubuntu.
Best Answer
You have to enable port forwarding in VirtualBox. You can do that by using the
VBoxManage
command. For example: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).