【问题标题】:Why do these iptables rules block http为什么这些 iptables 规则会阻止 http
【发布时间】:2014-09-01 11:41:03
【问题描述】:

我刚刚在全新的 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  

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

ACCEPT     all  --  anywhere             anywhere            

这似乎是在说“对于任何协议,从任何来源,到任何目的地,都接受”

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

谁能解释一下为什么上述规则不允许传入的http连接?

【问题讨论】:

    标签: centos firewall iptables


    【解决方案1】:

    我自己想通了。难怪我很困惑 - 列表没有显示完整的故事。我使用 -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 
    

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

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

    希望这能帮助人们不再像我一样困惑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2015-02-26
      • 2022-06-28
      相关资源
      最近更新 更多