Port forwarding, apache, connect but no response

Discussions related to using VirtualBox on Linux hosts.
Post Reply
csavery
Posts: 16
Joined: 5. Feb 2008, 07:53

Port forwarding, apache, connect but no response

Post by csavery »

Hello,

I am trying out virtualbox as a test platform for website development.

I have host as Fedora 7, guest as Centos 5.

Guest is setup as server with apache, mysql etc.

I have configured host to use port forwards as described in docs and it's working fine for ssh 2222 > 22 in guest. I can login and do work using ssh.

I have configured host 8080 > 80 in guest amd 1443 > 443 in guest as well.

When I try to get a web page (using either Firefox or wget) via localhost:8080 in host I get a connect message but then it hangs and gets no response. Eventually it times out with no result page.

The apache server is responding withing the guest. I can use wget in the guest and get the web page. netstat shows that apache is listening on 80 in the guest.

netstat shows that ports 8080 and 1443 are listening in the host and being serviced by virtualbox program.

So... any ideas why port 8080 is not getting forwarded correctly? Did I miss some other setting? Does virtualbox only forward one port (2222) and cannot handle more than one? Can't figure out whats broken here but seems to be happenign in forwarding mechanism of virtualbox.

Thanks in advance for any help here.
Chris :)
csavery
Posts: 16
Joined: 5. Feb 2008, 07:53

Post by csavery »

Ok. Figured it out. Firewall installed by default in guest was blocking access.
I didn't realize that Centos 5 was installing some default iptables rules.

Anyway, I replaced that with apf as that is what I usually use and opened the needed ports and it works fine now. Just super.

Sorry to bother anyone here.

Chris :)
csavery
Posts: 16
Joined: 5. Feb 2008, 07:53

Post by csavery »

I just wanted to note another thing for anyone doing a similar setup as this.
I started out port forwarding 8080 > 80 for the apache server in the guest box.
If you want to host the server in guest on the normal http port (80) then you are prevented due to the guest box being run as a normal user w/o su privileges. I got around this by adding an iptables routing rule to my rc.local so that port 80 was routed to 8080 on the host. This worked fine but you have to use the right rule as it is for localhost that the routing needs to be present not for external sites. Or at least this is what I found out. The rulethat I found worked was:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080

This gets added after all my other firewall rules in host os.

Now I can run 3 systems in one here: My normal Fedora desktop, my server Centos 5 and then WinXP in a box as well for testing browsers under Windows too.

I have to say that VirtualBox has done all this with ease and flying colours.
GREAT STUFF.

Chris :)
Post Reply