Portforwarding from host to guest using port 80, but it doesn't work

I installed ubuntu server inside a virtual box(11.04), then i configured apache.

Inside virtual box setting, i made a port forwarding from port 80(host) to 80(guest), i open my web browser on my host, and i go to http://localhost DON'T work, but if i go to http://localhost:1080, it work, but i didn't make a port forwarding from 1080 to 80, i have no 1080 in my configuration, what i want to know is why it does this?

I know that port 80 won't work until i launch the virtualbox as root, but what i don't know is why does it actually transform the port 80 to 1080 when it could just not work... is there something in virtualbox that see when its not root and transform address below 1024 to something else?


Solution 1:

The VirtualBox manual says:

Forwarding host ports < 1024 impossible:

On Unix-based hosts (e.g. Linux, Solaris, Mac OS X) it is not possible to bind to ports below 1024 from applications that are not run by root. As a result, if you try to configure such a port forwarding, the VM will refuse to start.

I guess this is the reason for getting port 80 forwarded properly when the host was run as a root user. Anyway I am not sure why the port is changing automatically from 80 to 1080.

Solution 2:

There is a nice section explaining port forwarding with NAT on Virtualbox here:

http://www.virtualbox.org/manual/ch06.html#natforward

I am not sure why your are seeing the behavior you are, can you post your configuration ?

The other (potential) solution is to use bridged networking. Personally I find bridged networking is easier to configure. If I feel I need a firewall, I configure it from the guest. You can easily limit port 80 to your host or lan with ufw.

sudo ufw enable
sudo ufw default deny
# change "192.168.0.10" to your host
sudo ufw allow proto tcp from 192.168.0.10 to any port 22
# Or for you LAN
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 80

You can change "any" to your IP if you wish.