首先,端口25是打开的,但是无法收到任何包。
我尝试了内部telnet连接来发送邮件,来确认Postfix在SMTP协议中是否配置的有问题。如下:
[root@myhost ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 xxxx.com ESMTP Postfix (CentOS)
helo xxxx
250 xxxx.com
mail from:<user2@xxxx.com>
250 2.1.0 Ok
rcpt to:<user1@xxxx.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
from:user2@xxxx.com
to:user1@xxxx.com
subject:Testing email
test test
.
250 2.0.0 Ok: queued as CBE5F6039
quit
221 2.0.0 Bye
Connection closed by foreign host.
然后我访问了Dovecot的mailbox, 显示确实收到了邮件:
./new
./new/1693231789.M572537P2155.xxxx,S=495,W=510
于是我又尝试了tcpdump -i any port smtp
来确认25端口是否能收到包。可是当我telnet 25端口的时候,tcpdump没有输出任何内容。
所以我又尝试了465端口,但是好像是出错了。
Postfix无法监听465端口的任何内容,也许是单纯地配置错误,也许是Linux阻挡了Postfix监听465端口的流量。
我首先尝试了在云服务器上tcpdump -i any port smtps
,然后从本机telnet mail.xxxx.com smtps
。服务器端显示tcpdump确实收到了我的telnet包,但是Postfix却没有监听到,而且没有任何反应。所以我查看了日志文件/var/log/maillog
,里面完全是空的,Postfix没有监听到或者根本没有监听465端口的包。所以我猜测也许是Linux的某种设置/防火墙阻挡了Postfix监听465端口的流量。
然后我又尝试了从服务器telnet465端口,但是报了错
我在服务器上telnet:
[root@myhost ~]# telnet localhost smtps
Trying ::1...
Connected to localhost.
Escape character is '^]'.
helo xxxx
Connection closed by foreign host.
打完一个helo直接就挂掉了……所以我又去看了/var/log/maillog
, 输出日志如下:
Aug 28 13:45:57 xxxx postfix/smtps/smtpd[1974]: connect from unknown[::1]
Aug 28 13:46:01 xxxx postfix/smtps/smtpd[1974]: SSL_accept error from unknown[::1]: -1
Aug 28 13:46:01 xxxx postfix/smtps/smtpd[1974]: warning: TLS library problem: 1974:error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol:s23_srvr.c:640:
Aug 28 13:46:01 xxxx postfix/smtps/smtpd[1974]: lost connection after CONNECT from unknown[::1]
Aug 28 13:46:01 xxxx postfix/smtps/smtpd[1974]: disconnect from unknown[::1]
以下是我的一些配置文件:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = localhost, localhost.$mydomain
mydomain = xxxx.com
myhostname = xxxx.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
recipient_delimiter = +
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_tls_security_level = may
smtpd_banner = $myhostname ESMTP $mail_name (CentOS)
smtpd_sasl_security_options = noanonymous, noplaintext
smtpd_sasl_tls_security_options = noanonymous
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/letsencrypt/live/xxxx.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/xxxx.com/privkey.pem
smtpd_tls_security_level = may
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
/etc/postfix/main.cf
mail_owner = postfix
myhostname = xxxx.com
mydomain = xxxx.com
# TLS parameters
smtpd_tls_cert_file=/etc/letsencrypt/live/xxxx,com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/xxxx.com/privkey.pem
smtpd_use_tls=yes
smtpd_tls_auth_only = yes
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtpd_sasl_security_options = noanonymous, noplaintext
smtpd_sasl_tls_security_options = noanonymous
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
# Enable IPv4, and IPv6 if supported
inet_protocols = all
mydestination = localhost, localhost.$mydomain
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
recipient_delimiter = +
virtual_transport = lmtp:unix:private/dovecot-lmtp
/etc/postfix/master.cf
:smtp inet n - n - 1 postscreen
#smtpd pass - - n - - smtpd
#dnsblog unix - - n - 0 dnsblog
#tlsproxy unix - - n - 0 tlsproxy
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_reject_unlisted_recipient=no
#-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
465 inet n - - - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_reject_unlisted_recipient=no
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
#-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
楼主好,我用GPT4.0,根据你的描述,分析的结果:
根据您所提供的信息,以下是一些建议和检查步骤:
1.25端口:
如果使用telnet localhost 25可以连接但是从其他机器使用telnet连不上,这通常是防火墙或安全组策略阻止的。
首先检查Linux的防火墙设置是否允许25端口。使用firewall-cmd或iptables工具(取决于您使用的是firewalld还是iptables):
# 使用firewalld
firewall-cmd --list-all
或
# 使用iptables
iptables -L -n -v
如果您在云服务器上,也检查云提供商的安全组或网络防火墙规则,确保25端口是开放的。
2.465端口:
从日志看,当你尝试用telnet连接465端口时,出现了SSL错误。这是因为465端口需要一个安全连接(SSL/TLS),而telnet提供的是一个纯文本连接。你应该使用openssl工具来测试:
openssl s_client -connect localhost:465
检查SSL/TLS证书和密钥的路径是否正确,并且Postfix有权限读取它们。
ls -l /etc/letsencrypt/live/xxxx.com/
再次,确认防火墙和云安全组策略允许465端口。
3.Postfix配置:
您在/etc/postfix/main.cf中多次定义了inet_interfaces,只有最后一个会生效。当前设置为localhost,这意味着Postfix只在本机监听。如果您希望Postfix从外部接受连接,您应该设置为all。
inet_interfaces = all
重启Postfix以应用任何更改:
systemctl restart postfix
4.其他检查:
确保Dovecot的认证守护进程正在运行,并且Postfix可以连接到它。根据您的配置,它应该在private/auth。
ls -l /var/spool/postfix/private/auth
检查Postfix和Dovecot的日志以获取任何其他可能的错误或警告。
结合GPT给出回答如下请题主参考
您好,通过您提供的信息,我们可以初步判断可能存在以下几个问题导致25端口无法收到任何包:
防火墙可能阻塞了25端口的流量,请检查防火墙规则,确保25端口是允许的。
Postfix配置可能存在问题,请检查Postfix配置文件中的smtpd_listen_address和smtpd_listen_port参数配置是否正确,是否与主机网络设置相匹配。
网络连接可能存在问题,请检查主机和其他设备之间的网络连接,确保网络连接稳定。
对于465端口无法被Postfix监听的问题,可能存在以下几个原因:
Postfix未正确配置smtps协议,请检查Postfix配置文件中的smtpd_tls_wrappermode和smtpd_tls_security_level参数配置是否正确。
证书配置可能存在问题,请确保Postfix配置中的smtpd_tls_cert_file和smtpd_tls_key_file参数指向正确的证书文件路径。
端口占用可能导致465端口无法被Postfix监听,请检查其他应用程序是否占用了该端口,如果是,请关闭该程序或更改Postfix监听端口。
希望以上信息对您有所帮助,如果问题仍然存在,请提供更多详细信息以便更准确地解决问题。