19

I have a linux server on configuration with apache. However I cannot get access to it using a remote computer.

I can ssh to the server normally.

my IP table:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

netstat -ant

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 SERVERIP:80                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:45117               0.0.0.0:*                   LISTEN
tcp        0    196 SERVERIP:22                 MyIP:3149                   ESTABLISHED
tcp        0      0 :::111                      :::*                        LISTEN
tcp        0      0 :::22                       :::*                        LISTEN
tcp        0      0 :::47193                    :::*                        LISTEN

using Curl SERVERIP:80 and curl localhost:80, both return default page from apache.

What could be the problem?

0

6 Answers 6

33

You need to enable access to your server on port 80 as it is currently being blocked by iptables.

sudo /sbin/iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

This will insert the rule into your iptables configuration at the start. Once you have done this and tested that it works then you should save the configuration so that it it is used next time the service starts,

sudo /sbin/service iptables save

this will write the current configuration to /etc/sysconfig/iptables.

If you use CentOS 7 then FirewallD is the right way to go:

firewall-cmd --zone=public --add-port=80/tcp

Verify with your browser that it works, and then:

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

To make changes permanent

0
1

Your iptables rules only allow incoming connections on port 22. Open up port 80 as well.

3
  • ...and the cmd is iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT Aug 17, 2011 at 9:11
  • ...which is correct, but won't work, because it will append this rule behind the one which REJECTs all incoming connections not ACCEPTed earlier. Aug 17, 2011 at 9:17
  • That's true, I'm just used to adding it to the rules file into the correct position, forgot to mention. iptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited, then the previous, then add the deny-all catchrule with iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited Aug 17, 2011 at 9:24
0

You can also use the default http service directly

firewall-cmd --permanent --zone=public --add-service=http

0

you can use -I instead of -A and the cmd is iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

0

Use a online port checker and check the port is indeed open, If not a possible reason might be your ISP is blocking it. (Optimum does). Call your ISP and ask them to open it.

0

In Linux, it could be that firewall has blocked port 80, and it needs to be enabled.

I was using Centos/Linux and was getting error : Firewalld.service: Unit not found.

So I did the following, and it worked

  1. sudo yum install firewalld
  2. sudo systemctl start firewalld
  3. sudo systemctl enable firewalld
  4. sudo firewall-cmd --permanent --add-port=80/tcp
  5. sudo firewall-cmd --reload
2
  • With the steps above you deploy a completely new firewall management tool which doesn't import any an existing firewall configurations in the rulesets it will deploy. In other words: although you now open port 80 for http you lock out remote ssh access that was enabled before.
    – HBruijn
    Aug 1, 2023 at 11:52
  • may be, but I am still able to connect with ssh Aug 2, 2023 at 6:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .