Forwarding port 80 on host

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
tim_linquist
Posts: 2
Joined: 29. Nov 2010, 04:23
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu Hardy Heron

Forwarding port 80 on host

Post by tim_linquist »

Evening,

So I'm attempting to forward traffic on port 80 of the host to port 80 on the guest to no avail. I've added the necessary settings to virtualbox (on host):

VBoxManage getextradata "vagrantbase_1_6" enumerate
Oracle VM VirtualBox Command Line Management Interface Version 3.2.10
(C) 2005-2010 Oracle Corporation
All rights reserved.

Key: GUI/LastGuestSizeHint, Value: 720,400
Key: GUI/LastWindowPostion, Value: 482,166,720,422
Key: GUI/MiniToolBarAlignment, Value: bottom
Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/ShowMiniToolBar, Value: yes
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort, Value: 22
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort, Value: 2222
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol, Value: TCP
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/web/GuestPort, Value: 80
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/web/HostPort, Value: 80
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/web/Protocol, Value: TCP

Incoming traffic over TCP should also be allowed (from guest) :

sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Despite this and many other attempts I am unable to forward port 80 on the host and am thinking I am going about this the wrong way. Is it even possible for virtual box to listen on port 80 of the host and forward traffic to the guest? I have yet to encounter any errors in the vm log which is why I've continued to try and get this to work. The only other solution I can think of is to hack the local DNS registry and forward requests for relevant domains to the VM but that is DEFINITELY not desirable.

Thanks, Tim
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Forwarding port 80 on host

Post by Sasquatch »

Does SSH work? If so, then the problem is the privileged port you run the VM on. In order to forward ports below 1024 requires administrative privileges. You have to modify the forwarding rule to use a port above 1024, like 8080.
Another thing that I see is the forwarding rules itself, including the adapter type. Is the Guest still configured to use the PCNet adapter, or is it using a different one? The method for creating forwarding rules has also changed in the recent versions. It's now in the following syntax:

Code: Select all

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
tim_linquist
Posts: 2
Joined: 29. Nov 2010, 04:23
Primary OS: Mac OS X Leopard
VBox Version: OSE Debian
Guest OSses: Ubuntu Hardy Heron

Re: Forwarding port 80 on host

Post by tim_linquist »

Thanks Sasquatch. Yes, I can ssh (as it's forwarding 2222 > 1024.) I have since done more research and found out that for my needs I should change the adapter to 'bridged'. This way I can see the guest as if it were just another machine on the LAN. Once I get 'bridge' mode operational I'll be able to modify my /etc/hosts file and forward domains to the ip of the guest. This is all a little over my head which is why I was attempting to get the forwarding to work and still operate in NAT mode.

Do you know if there is any way to bind an ip address to a guest in NAT mode? If VirtualBox can listen for an ip and forward traffic to a port on the guest that'd resolve my conundrum much easier.

Tim
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Forwarding port 80 on host

Post by Sasquatch »

With NAT, VB listens on all the IP addresses the Host has to forward data to. So if you have two interfaces, one wifi and one wired, with two different address ranges, both will give the VM on the same port. Doing it from the Host and call forth localhost:<forwarded port> will give you the Guest.
Of course, you can bind it to one of the Host IP addresses. That's in the manual, chapter 6.1 I think, which describes the port forwarding and NAT.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Post Reply