4

So i'm trying to forward the guest port 80 to my host port 80 so that I can view the apache running on my guest in my host's browser.

If I set the following: (8080/80), I can view localhost:8080 and see the guest apache server.

port 80

When I set host to 80 and guest to 80, it doesn't work. How would I get guest 80 to direct to host 80?

Assume running in NAT mode is mandatory.

2 Answers 2

7

From your screenshot, it appears that you are running VirtualBox on OS X - is that correct?

If so, by default - a user account can not create IP endpoints that listen on ports below 1024. You are left with two choices if you absolutely need to have something listening on a low port number:

  • You can run VirtualBox as root (or other privileged account) - but this not a recommended solution as it tends to bypass a lot of the security restrictions.
  • You can add a forwarding rule to your firewall, say from port 8080 to 80, to silently redirect the traffic for you. Your VirtualBox would still be configured to forward port 8080. In a nutshell:

    • Open a Terminal, and type sudo vi /etc/ipfilter/ipfw.conf
    • Add this line: add 12001 fwd 127.0.0.1,8080 tcp from any to me dst-port 80
    • Save and close the file: :wq

Disclaimer: I don't have a Mac in front of me, let alone a recent copy of OS X - so while the high-level ideas still apply, the actual details of configuring the firewall forwarding rules may be slightly different depending on which version you are currently running.

There may be better ways still to handle this. For example, if you configure a second virtual adapter for your guest and configure it as "Host-Only" you can then access any of the ports on the guest from your host without having to forward any of the ports. This may not make sense if you need to share the guest across your network - in which case perhaps the "Bridged" virtual adapter would make more sense. I would suggest reading up on the different networking modes in Chapter 6 of the VirtualBox Manual: https://www.virtualbox.org/manual/ch06.html

3
  • that works beautifully. is 12001 arbitrary?
    – tester
    Aug 27, 2012 at 20:28
  • The 12001 is more or less arbitrary - you can think of it as a "rule number" if you would like, it is any number between 1..65535. More info: freebsd.org/doc/en_US.ISO8859-1/books/handbook/… - specifically section 31.6.5.1.2
    – Goyuix
    Aug 27, 2012 at 20:32
  • 2
    I'm on OSX 10.8, and just a quick update: sudo ipfw add ... has the same effect since 10.8 doesn't have an /etc/ipfilter/ipfw.conf file.
    – Tom
    Nov 15, 2012 at 6:09
0

it's possible that port 80 is blocked by your ISP yet it works fine for VirtualBox, how do you check? provide more details.

4
  • I have virtualbox running on this same machine. ISP is not a factor.
    – tester
    Aug 27, 2012 at 18:41
  • use netstat to see what's listening on your port 80 BEFORE you run VirtualBox to make sure there is no other binding happening
    – alexus
    Aug 27, 2012 at 18:56
  • nothing on the host machine seems to be using port 80. any idea what else it might be?
    – tester
    Aug 27, 2012 at 18:59
  • make sure you use netstat to verify that and if that's the case run your VirtualBox and verify again with netstat that binding did happened
    – alexus
    Aug 27, 2012 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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