I'm setting up a VirtualBox with CentOS so I can test out all my code, etc. on a Linux box instead of the Windows I use for development.

I just got the SSH working (I SSH to localhost:2222 and it port forwards it to the virtualbox port 22).

I'm trying to do the same thing with Apache, to get a web server up and running.

I've portforwarded port 8888 on localhost to port 80 in my CentOS Virtualbox, but I can't seem to access anything with localhost:8888 in my browser?

Apache is also definitely running:

ps -e | grep httpd
2108  ?      00:00:00 httpd
2110  ?      00:00:00 httpd
2111  ?      00:00:00 httpd
2112  ?      00:00:00 httpd
2113  ?      00:00:00 httpd
2114  ?      00:00:00 httpd
2115  ?      00:00:00 httpd
2116  ?      00:00:00 httpd
2117  ?      00:00:00 httpd


[root@CentOS /]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Fri Jan 27 18:26:36 2012
:OUTPUT ACCEPT [32:2278]
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
# Completed on Fri Jan 27 18:26:36 2012

Nmap output:

[root@CentOS conf]# nmap localhost

Starting Nmap 5.21 ( http://nmap.org ) at 2012-01-28 00:58 WST
Nmap scan report for localhost (
Host is up (0.0000090s latency).
Hostname localhost resolves to 3 IPs. Only scanned
Not shown: 993 closed ports
22/tcp  open  ssh
23/tcp  open  telnet
25/tcp  open  smtp
80/tcp  open  http
111/tcp open  rpcbind
443/tcp open  https
631/tcp open  ipp


I believe the default CentOS firewall only allows port 22 for SSH. Since I assume you are running the VirtualBox VM on a protected network it would be safe to run the following as root to disable your firewall:

/etc/init.d/iptables stop

This is assuming that you are doing your port redirection on the Windows host machine. If you are doing redirection with iptables then this will kill your redirection as well. You could post /etc/sysconfig/iptables so we can look at your firewall configuration to see if your machine is blocking port 80.

| improve this answer | |
  • Stopped iptables, and posted the file in the OP – user1045696 Jan 27 '12 at 15:13
  • 1
    Firewall rules look good. Can you connect to port 80 on your VM from your VM? Telnet is good for testing this. telnet [vm ip] 80 and telnet 80 . Try them both. If it only connects to then apache is only binding to the loopback interface (lo) – chuck Jan 27 '12 at 17:15
  • What do you have for "Listen" lines in your httpd.conf file? Are you doing anything with Virtual Hosts that would try and bind to a certain IP address? – chuck Jan 27 '12 at 18:07
  • Neither or [vm ip] works for telneting to port 80. It gets to connecting to [ip], and then says connection closed by foreign host. For the listen lines, it says listen 80 – user1045696 Jan 28 '12 at 2:17
  • I screwed up. I should have told you to run netstat -tlpn That will give you a list of all listening TCP ports on your machine and what program is doing the listening. – chuck Jan 29 '12 at 13:54

On a fresh install of CentOS7, do the following after installing Apache & starting service:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Now Apache should be reachable from your host.

| improve this answer | |

You shouldn't use localhost, use its IP address instead.

| improve this answer | |
  • For some reason that just doesn't work. I tried SSHing to and it doesn't work, just comes up with a blank screen in putty. But then localhost:2222 works fine, which I'm not too sure why. – user1045696 Jan 27 '12 at 14:32
  • You did a port forward to 2222 so why are you trying to ssh to port 22? – Metalmini Jan 27 '12 at 14:52
  • SSH works fine, but I portforwarded localhost port 2222 to (which is my virtual machine) – user1045696 Jan 27 '12 at 15:12
  • is the VM's private network. That is most likely a different subnet than your host's IP address. You couldn't even ping your VM. – Chloe Mar 17 '17 at 8:18

This question is more detailed than what I searched for, but for all future visitors:

On a standard freshly installed CentOS (in my casae 6.4) the iptables service (firewall) is blocking access to apache from outside localhost.

Typing service iptables stop stops the service and should allow access.

| improve this answer | |

You might have something else on port 8888 or some firewall on windows (including one included)

They even block local MS-SQL server sometimes like after 10 connections. No need to imagine - just dig up firewall blocking logs.


Have you seen reject logs of your firewall or just keep chanting? Most antiviruses will try to clamp mass-mailing worms and other malware by behavior. Like McAfee blocks thunderbird after 5 mails in 30 minutes....

| improve this answer | |
  • I'll try changing port. However, I can't see the firewall affecting anything, because SSH worked fine? – user1045696 Jan 27 '12 at 14:26

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.