Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port forwarding from Host port 80 to VirtualBox port 80 doesn't work

I have read VirtualBox port forwarding guide, similar questions in this site and other sites but couldn't find a solution.

UFW is enabled on Guest OS (Ubuntu), port 80 and 22 are open. I can ssh from host to ubuntu and can access ubuntu site from host browser.

On Guest, I setup Nat and hostonly (vboxnet3) adapters. Also opened router port 80 (192.168.1.90) Guest ip is 192.168.70.10

So In guest settings > Nat >port forwarding I put:

TCP host-ip: 192.168.1.90 host-port:80 guest-ip:192.168.70.10 guestost-port:80

However, this setting doesn't work. I appreciate if you direct me to the right path.

like image 899
john206 Avatar asked Jul 09 '12 03:07

john206


People also ask

Why can't i port forward port 80?

In simple words, it looks like the port 80 is reserved to the router management routine, regardless of any other rule you set. Even if you set a different port for that. This means that this router does not allow customers to set up a web server, since port 80 can't be used.

Can I use port 80 for port forwarding?

Port 80 is the default port for HTTP (Hyper Text Transfer Protocol). Most servers and system across the globe use Port 80. It is very common for Internet Service Providers (ISP) to block all data to this port. You can resolve this by redirecting traffic to a different port using our Port 80 Redirect service.

What port does VirtualBox use?

Ports 22, 443, 3389, 18083, and 49152-65534 are configurable. On VirtualBox hosts, the HTTPS port is configured when you install VirtualBox. The VRDP ports are only required if the VRDP protocol is used to connect to desktops.

How do I expose a port in VirtualBox?

To enable port forwarding, open the settings for your Virtual Machine. Verify that NAT is selected in the Attached to: selector. At the bottom of the window, click on the Port Forwarding button. You are then presented with a form where you can add new forwardings.


2 Answers

As William mentioned, a linux/unix OS won't let a process listen on ports < 1024 unless they're run as root. You could run VirtualBox as root, although I've read dire warnings on doing that. It's probably horribly insecure.

Instead, set up Apache2 on the host system to listen on port 80 (it should be set up for that already), but instead of serving a website on the host machine, have it proxy traffic to some higher port - say, 8080 - on the host.

Then, have VirtualBox forward that higher port to the guest OS port 80.

The Apache setup would be something like this:

  1. Install the HTTP proxy module

    a2enmod proxy_http

  2. Make sure /etc/apache2/ports.conf has a Listen 80 directive in it

  3. Add another site in /etc/apache2/sites-available or modify the default site (or just slap this in ports.conf)

    <VirtualHost *:80>
        ProxyPreserveHost On
        ProxyRequests Off
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
    </VirtualHost>
    
  4. bounce apache

    service apache2 restart

The VirtualBox setup would be host port: 8080, guest port: 80.

Traffic would go:

client --> host:80 --> Apache --> host:8080 ---> vbox NAT ----> guest:80

This is similar to William's ssh tunnel, but doesn't require manual intervention (re-entering a password) every time the host is rebooted.

like image 116
Peter Avatar answered Oct 17 '22 17:10

Peter


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

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.

It is possible to run VirtualBox as root, which -will- allow you to forward Host ports < 1024, so if you are adamant about doing this with VirtualBox, you can become root and execute VirtualBox this way:

$ sudo su -
# VirtualBox
like image 35
William Drury Avatar answered Oct 17 '22 16:10

William Drury