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