端口 80 连接被拒绝

Hol*_*ill 6 server iptables networking nginx

我无法连接到我的网络服务器上的端口 80。我的 iptables 处于默认状态:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

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

当我启动不同的服务器(nginx、nodejs ...)时,我可以让它们监听端口 80,但尝试访问时,我总是得到“连接被拒绝”。收听任何其他端口(81,8080 随便什么)都可以正常工作。只有端口 80 以某种方式被阻止。通过 localhost 访问端口 80 确实有效,因此出于测试目的,我什至切换了外部防火墙,但仍然没有运气。我该怎么做才能找出谁阻止了这个端口 80?

根据要求 netstat -tlpn 的输出(在端口 80 上运行 nginx 时):

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      710/vsftpd      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1179/sshd       
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1661/master     
tcp        0      0 0.0.0.0:5984            0.0.0.0:*               LISTEN      980/beam.smp    
tcp        0      0 87.106.64.11:3306       0.0.0.0:*               LISTEN      1346/mysqld     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3274/nginx: master 
tcp6       0      0 :::22                   :::*                    LISTEN      1179/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      1661/master  
Run Code Online (Sandbox Code Playgroud)

Hol*_*ill 8

我做了一个tcptraceroute 87.106.64.11 80,它绝对是我的服务器阻塞了端口。在跟踪中的某个时刻,我得到了这个:

s18132051.onlinehome-server.info (87.106.64.11) [closed]
Run Code Online (Sandbox Code Playgroud)

所以我重置了我的 ip 表,这就成功了。

所以要么表里有一些隐藏的规则,要么iptable -L没有给我所有的规则。我会将此标记为答案,因为它解决了问题。
我仍然很想听听,为什么我在做的时候没有任何阻止规则iptables -L


小智 6

我遇到了同样的问题,但在 Debian 8.4 (Jessie) 上。与上面一样,解决方案是http://insanelabs.net/linux/linux-reset-iptables-firewall-rules/ 中列出的 IPTables 刷新脚本。虽然 iptables 没有报告任何规则,但一定有一些“隐藏”的规则,或者 iptables 本身的错误。我正在向 Debian 维护者报告这个错误。

如果链接的站点出现故障,这里是有问题的脚本的全文,为方便起见,在此处复制。

#!/bin/sh
echo "Flushing iptables rules..."
sleep 1
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
Run Code Online (Sandbox Code Playgroud)