尝试设置邮件服务器,无法让端口 (25, 587) 工作

rea*_*ilt 9 email smtp postfix centos

我到处搜索,我真的在为这个而苦苦挣扎。我想我已经尝试了几乎所有的东西。

背景资料

  • 使用 CentOS 6.7 的 VPS
  • 后缀 2.6.6
  • dovecot、amavis、mysql、fail2ban
  • 我已经与我的 VPS 提供商确认他们没有阻止任何端口。

我做过的事

  • 删除了股票发送邮件
  • 我已经安装了 postfix、dovecot、mysql 等,以获得完整的邮件解决方案
  • 我只允许 imap、smtp 和 STARTTLS(端口 143 和 587)
  • 禁用 SSH 登录,仅使用密钥
  • 我可以接收邮件(通过端口 143)
  • 我可以从 localhost telnet 到两个端口 (587, 25) 并且我收到 postfix 问候
  • 尝试连接到 587 或 25(邮件客户端或 telnet)得到零响应,即连接超时

我尝试过的事情

1)端口是否开放?是的,iptables:

Chain INPUT (policy DROP 11 packets, 1375 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:587
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:587
   25  2579 f2b-dovecot  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           multiport dports 110,995,143,993,587,465,4190
   68  7788 f2b-postfix  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           multiport dports 25,465,587
    0     0 f2b-sshd   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           multiport dports 22
   25  2579 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:143
    7   600 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8080
23464 2662K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
   49  2940 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:3915
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:80
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:443
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:143
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:587
    5   300 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:25

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 23235 packets, 2494K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain f2b-dovecot (1 references)
 pkts bytes target     prot opt in     out     source               destination
   25  2579 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain f2b-postfix (1 references)
 pkts bytes target     prot opt in     out     source               destination
   68  7788 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain f2b-sshd (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)

2) postfix 是否监听 587 端口?是的。它只在本地主机上监听吗?不,任何主机。

这是netstat:

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:25                  0.0.0.0:*                   LISTEN      7173/master
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      917/httpd
tcp        0      0 127.0.0.1:4190              0.0.0.0:*                   LISTEN      749/dovecot
tcp        0      0 0.0.0.0:587                 0.0.0.0:*                   LISTEN      7173/master
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      749/dovecot
tcp        0      0 127.0.0.1:24                0.0.0.0:*                   LISTEN      749/dovecot
Run Code Online (Sandbox Code Playgroud)

这里还有 postfix/main.cf,以防万一:

# Enable both IPv4 and/or IPv6: ipv4, ipv6, all.
inet_protocols = ipv4

# Enable all network interfaces.
inet_interfaces = all
Run Code Online (Sandbox Code Playgroud)

3)您是否正确强制安全连接?据我所知,是的,这里是 postfix/master.cf:

# Submission, port 587, force TLS connection.
submission inet n       -       n       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o content_filter=smtp-amavis:[127.0.0.1]:10026
Run Code Online (Sandbox Code Playgroud)

4) smtpd 限制怎么样?看起来没问题:

# HELO restriction
smtpd_helo_required = yes
smtpd_helo_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_non_fqdn_helo_hostname
    reject_invalid_helo_hostname
    check_helo_access pcre:/etc/postfix/helo_access.pcre
Run Code Online (Sandbox Code Playgroud)

5) postfix 还能正常工作吗?

是的,登录服务器并从控制台发送测试邮件有效,另一端收到电子邮件,即:

echo "Test mail from postfix" | mail -s "Test Postfix" user@something.com
Run Code Online (Sandbox Code Playgroud)

6) 在端口 587 上连接时会发生什么?

显然,什么都没有。如果我尝试 telnet 到任何随机端口,我至少会得到一些东西。例如,尝试 telnet 到端口 666(未打开)不会对客户端产生任何回复,但至少我在 tcpdump 中得到了一些信息:

15:22:20.305697 IP xxx > xxx.com.mdqs: Flags [S], seq 3195304468, win 8192, options [mss 1352,nop,wscale 8,nop,nop,sackOK], length 0
Run Code Online (Sandbox Code Playgroud)

当 tcpdumping 端口 587 时,尝试 telnet 到它时绝对不会发生任何事情。

我还缺少什么?

以上一切都耗尽了我对我仍然可以尝试的事情的了解。我已经设法将其确定为我的端口 587 被某些东西完全封锁了。正如我所说,我的 VPS 提供商确认他们根本没有阻止任何端口。我试过端口 25,也是一样的情况。

我唯一能看到的另一件事是我在设置服务器时以某种方式阻止了这些端口,但我不记得是否是这种情况,我不知道如何进行测试。

我真的很感激你能给我的任何帮助。事实上,我正在为帮助我解决这个问题的人购买啤酒,我已经浪费了两天时间,而且开始变得非常烦人。

Mad*_*ter 4

Reachergilt,欢迎来到 SF,感谢您提出的第一个问题。您可能会觉得我们救了您,但说实话 - 您已经完成了所有繁重的工作,并且非常系统地呈现了它。怀着这样的法医心态,我希望你在未来一段时间内留在这些部分。

输出tcpdump尤其可恶。毫无疑问,您的连接尝试甚至没有到达您的服务器,这证明了服务器的防火墙、postfix绑定以及服务器端的其他一切都是无罪的。

有了这个指针,您就可以离开并确认您的出站连接被阻止,因此您的测试永远不会到达您的服务器。现代网络中 25 个(在较小程度上是 587 个)的出站被阻止是相当(令人沮丧)正常的,因为垃圾邮件发送僵尸网络使用它们。

无论如何,您现在很高兴您的新邮件服务器能够像宣传的那样工作,这很好。

  • 是的,我的帖子确实为有类似问题的人提供了一个很好的清单。有趣的是,因为我认为我的服务器出了问题,所以我从头到尾检查了所有内容,以便我可以在这里记录所有内容。 (3认同)