Issue #1 - VM networking types
There are 3 modes of networking:
- NAT
- Host Only
- Bridged
Details on setting them up
When to use each?
- #1: For development of Facebook/web apps that are on other servers
- #2: If you want to build your own app, and test it from the VirtualBox host (not just the guest VM)
- #3: If you want to build an app and test it from other systems on LAN
Issue #2 - firewall blocking?
Depending on which distro you're using, the firewall might be blocking your web browser from accessing your Apache instance. This would make sense given you're able to ping the system, but not access it via port 80, which is the port that Apache is listening on.
temporarily disabling it
On CentOS you use this command to disable it.
$ /etc/init.d/iptables stop
check that Apache's listening
You can also confirm that it's listening on this port.
$ netstat -antp | grep :80 | head -1 | column -t
tcp 0 0 :::80 :::* LISTEN 3790/httpd
confirm firewall's off
The firewall can be confirmed that it's wide open.
$ 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
If this solves your issue then you can permanently add a rule that allows traffic in via TCP port 80.
adding a rule for TCP port 80
$ /etc/init.d/iptables restart
$ iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$ /etc/init.d/iptables save
NOTE: This will make the rule persist between reboots.
firewall is accepting TCP port 80
A system that has the port 80 open would look something like this:
$ iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:8834
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Issue #3 - Apache listening?
In the above issue we saw that Apache was listening, but sometimes it's mis-configured so that it's only listening on 1 IP address, or that it's listening on a different network interface. The command netstat
can be used to double check this as well as reviewing the Apache configuration files.
$ netstat -anpt | grep :80 | column -t
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1750/httpd
This shows that Apache is listening on all interfaces (IP 0.0.0.0).
I won't repeat what @Lekensteyn's answer which covers this particular issue in more details here.
References
:::80
, then Apache is only listening for IPv6 connections. Have you tried checked yourListen
directives?-p
flag tonetstat
to verify that you Apache is actually listening on port 80, and not some other service. Can you runcurl localhost
from the guest? What doesgrep -C3 -rni Listen /etc/httpd/
show?