大网数据广告活动
服务器运维问答

Why cannot I access my website when port 80 is not blocked?

· 52CE 我爱测

On my VPS(CentOS 7), the default iptables is: 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…

问题原文

原帖链接 · William · CC BY-SA 4.0

On my VPS(CentOS 7), the default iptables is:

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

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

I cannot visit my website set up using Apache/2.4.6, the browser displays: "The connection was reset".

If I insert a rule to accept tcp connection on port 80 in iptables using "iptables -I INPUT -p tcp --dport=80 -j ACCEPT", everything is ok, the website can be visited without problem. The iptables is:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80
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

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

I wonder why I should add the rule because in old iptables, the third rule is "ACCEPT all -- 0.0.0.0/0 0.0.0.0/0", which means it will accept all connections to all ports. Did I misunderstand something?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

Yes, you missed an important detail. But it's not your fault; this is very poorly documented and apparently not well known.

The iptables command has a significant design flaw: It doesn't actually display the complete firewall rule unless you use the -v command line option.

If you repeat the iptables command and add -v you will see that that rule accepts all traffic on the interface named lo, that is all localhost traffic.

target     prot opt in     out     source               destination 
ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           

Since iptables is now deprecated, and the flaw has been there basically forever, it is unlikely that this will ever be changed.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-09-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。