这个问题在这里可能有很多次的问题,但经过几次失败的尝试,我重复了这个历史:
如何在运行CentOS的服务器上打开端口25端口。
这是我的iptablesconfiguration:
Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- anywhere loopback/8 reject-with icmp-port-unreachable ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere tcp dpt:ftp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp ACCEPT icmp -- anywhere anywhere LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix `iptables denied: ' DROP all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination DROP all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp spt:ftp-data
这里是sudo netstat -plntu的输出
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1283/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1039/sshd tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 5981/master tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1297/php-cgi tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1177/mysqld tcp 0 0 :::22 :::* LISTEN 1039/sshd tcp 0 0 :::25 :::* LISTEN 5981/master
每当我尝试像这样的telnet
telnet 158.549.236.54 25
连接超时。 这里使用的IP是随机的。
问题不在于您的防火墙(您似乎在顶部添加了允许所有stream量的规则)。
你主要的问题是端口25只在127.0.0.1和:: 1上,这两个端口都是localhost。 您需要configuration您的SMTP服务器以侦听158.549.236.54接口(或所有接口)
configuration看起来很好(防火墙允许所有的stream量和邮件服务器暴露在:25),很可能你的ISP阻止到邮件端口的stream量(为了防止垃圾邮件的目的)。
一个解决方法是添加一个NATredirect到你的服务器从一个随机端口(比如说2525)到25端口iptables -t nat -I PREROUTING -p tcp --dport 2525 -j REDIRECT --to-port 25然后尝试telnetting到该端口: telnet ip 2525
我强烈怀疑问题是您的防火墙规则。 尽pipe第一条规则似乎允许一切,但这就是为什么iptables -L的输出比诊断这些问题更糟糕的原因 – 它没有给出接口限制 。
我怀疑如果你想粘贴iptables -L -n -v的输出,我们会看到第一条规则只适用于loopback接口上的stream量。
尝试
iptables -I INPUT 1 -p tcp --dport 25 -j ACCEPT
看看是否能解决任何问题。