Port forwarding from Host port 80 to VirtualBox port 80 doesn't work
Solution 1
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:
-
Install the HTTP proxy module
a2enmod proxy_http
Make sure
/etc/apache2/ports.conf
has aListen 80
directive in it-
Add another site in
/etc/apache2/sites-available
or modify the default site (or just slap this inports.conf
)<VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost>
-
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.
Solution 2
Here's another approach that could work if you are not comfortable running VirtualBox as the root user. You can use SSH to set up port forwarding from the host port 80 to some non-restricted port (in the example below, I use port 8080), which will then in turn be forwarded to guest port 80. Convoluted, but it works.
- Forward from host port 8080 to guest port 80. Make sure it is functioning by pointing a browser at port 8080 on your host machine.
- Make sure sshd is running on your host. In Mac OS X, go to
System Preferences -> Internet & Wireless -> Sharing
and make sureRemote Login
is checked. -
Become root on your host
$ sudo su -
-
Forward host port 80 to host port 8080 using SSH (the bind address
\*
makes the port available on all interfaces).# ssh yourusername@localhost -L \*:80::8080
Note that it will ask you to log in with whatever credentials you use for yourusername, so it will most likely ask for your password and when you are successful, actually log you in.
You should now be able to hit port 80 on your host machine and see the same service as hitting port 8080 on your host machine, aka port 80 on your guest OS.
If you don't want others on your network to be able to hit port 80 on that machine, but still want to be able to get to it from a browser on your host system, bind the port to localhost
:
# ssh yourusername@localhost -L localhost:80::8080
Solution 3
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
Related videos on Youtube
john206
Updated on April 12, 2022Comments
-
john206 about 2 years
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.
-
ramesh.mimit over 11 yearsI am also facing the same issue however port more than 1024 on host machine to guest machine 80 is working but port 80 of host machine to any port on guest machine is not working... I am using Virtual box on Mac. Please let me know if you find any solution to your problem?
-
-
Peter over 10 yearsIf your host OS is a *nix OS, you can use iptables to redirect traffic from port 80 to a higher port on the host OS. Sounds much better than involving Apache or SSL tunnels.
-
Michael Butler over 9 yearsIs it just as simple to forward SSL requests using the proxy module? i.e.
<VirtualHost *:443>
or are there additional steps? -
adowdy about 5 years@MichaelButler -- i had to set this up for SSL stuff, and worked out my own version of this solution with extra https / SSL stuff in the Apache2 config. detailed here: superuser.com/questions/1427245/…