Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
    
that works beautifully. is 12001 arbitrary? –  tester Aug 27 '12 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 '12 at 20:32
1  
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 '12 at 6:09
add comment

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

share|improve this answer
    
I have virtualbox running on this same machine. ISP is not a factor. –  tester Aug 27 '12 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 '12 at 18:56
    
nothing on the host machine seems to be using port 80. any idea what else it might be? –  tester Aug 27 '12 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 '12 at 19:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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