为什么这些iptables规则会阻止http

Dan*_*ard 1 firewall centos iptables

我刚刚在新的CentOS 6.5安装上安装了apache.我在浏览器地址栏中输入了ip地址,但无法连接.然后我关掉iptables,然后刷新,这次我可以连接.

所以很明显iptables阻止了http(端口80)流量.

所以我查看了iptables规则(在新的Centos安装后未触及):

[root@centos ~]# iptables --list
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     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

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

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  
Run Code Online (Sandbox Code Playgroud)

现在,我不是iptables专家,但我认为我理解它很好,可以解决这样一个简单的问题.但我很困惑,因为INPUT链中的第3行是这样的:

ACCEPT     all  --  anywhere             anywhere            
Run Code Online (Sandbox Code Playgroud)

似乎在说"对于任何协议,从任何来源,到任何目的地,接受"

所以我希望我可以连接到网站(tcp,端口80).但我不能.所以我一定误解了iptables的工作原理或者列表的含义.

任何人都可以解释为什么上述规则不允许传入的http连接?

Dan*_*ard 7

我自己想通了.难怪我很困惑 - 上市并没有显示完整的故事.我使用-v(详细)选项再次尝试了它.

[root@centos ~]# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
81194  118M ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere            
    7   364 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:ssh 
   21  2394 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited 
Run Code Online (Sandbox Code Playgroud)

特别是,它现在也显示了INTERFACE.第三条规则,我认为是非常宽松的,实际上并不宽容,因为它只适用于系统的内部环回地址.

因此,来自外部的HTTP请求将在以太网接口上接收,而不是环回,第3条规则不适用,因此唯一匹配的是最终的REJECT规则.

希望这会帮助别人不要像我一样困惑.