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

标签 centos firewall 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  

现在,我不是 iptables 专家,但我认为我已经足够了解它来解决像这样的简单问题。但我很困惑,因为 INPUT 链中的第 3 行是这样的:

ACCEPT     all  --  anywhere             anywhere            

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

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

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

最佳答案

我自己想通了。难怪我很困惑——列表没有显示完整的故事。我使用 -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。第三条规则,我认为是非常宽松的,实际上根本不是宽松的,因为它只适用于系统的内部环回地址。

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

希望这会帮助其他人不像我一样困惑。

关于centos - 为什么这些 iptables 规则会阻止 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24687697/

相关文章:

centos - 在 CentOS 上使用 Phalcon 的 Syslog

svn - 在 CentOS 上安装 JavaHL 1.6

mysql - 无法连接到 sql server

kubernetes - 为什么我的 Kubernetes pod 网络流量不经过 iptables NAT 表?

ruby-on-rails - 我显然遗漏了一些东西...... 'ruby' 不起作用但 './ruby' 起作用(centos 5.5,从源代码安装)

php - 如何为安装驱动程序php cpanel设置目录路径postgresql

java - 两个java流程实例之间的差异

https - 客户端防火墙阻止除 80 和 443 以外的所有端口,需要将端口 443 上的请求转发到 SSH 或 HTTPS

linux - Debian 8 上的 IPTables

node.js - 如何模拟 irc 服务器断开连接来测试我的 nodejs irc 机器人?