
如何讓我的 Postfix 伺服器僅在連接埠 587 上傳送郵件,並透過安全性驗證(使用系統 Linux 使用者)啟用連接埠 587 的 TLS?
首先,這個問題可能看起來太廣泛,但我在網路上找不到單一的解決方案。很多文章確實給出了解決方案,但他們跳過了一些部分。
我想強制身份驗證並強制 TLS 連線。
如果有人問我,我可以發布配置。
提前致謝。我是 postfix 的新手。另外,我可以看一下http://www.postfix.org/documentation.html,但在你告訴我之前,我無法正確理解它,因此,我確信我會弄亂配置,並使我的伺服器無法使用。另外,這裡的 postfix 是使用 apt 套件管理器安裝的。但我確信這與 ubuntu 沒有特別關係。在使用 postfix 之前我使用的是 Exim4,但是對 Exim 的支援很少,因為人們大多在 cPanel 中使用它,所以我沒有得到普通的 Exim 支援。
這需要緊急幫助,因為我們伺服器的安全處於危險之中。
答案1
若要啟用連接埠 587,請編輯文件/etc/postfix/master.cf
vi /etc/postfix/master.cf
並刪除該行前面的#(取消註解該行):
#submission inet n - n - - smtpd
使其看起來像這樣:
submission inet n - n - - smtpd
您可能需要取消註解此行之後啟用 SASL 驗證的其他行。每條新行都應以空格開頭!
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
所有其他設定都可以在/etc/postfix/main.cf根據您的環境。
此外,您可能需要設定 TLS 設定:
# TLS parameters
# you need to specify a real certificate location
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert.key
smtpd_use_tls=yes
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtp_tls_session_cache_database = btree:$data_directory/smtp_tls_session_cache
smtpd_sasl_tls_security_options=noanonymous
smtpd_tls_auth_only=yes
根據您是否使用 dovecot 接收電子郵件,您可能需要新增:
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
broken_sasl_auth_clients=yes
附加安全限制:
smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_non_fqdn_helo_hostname,reject_non_fqdn_sender,reject_unknown_sender_domain,reject_non_fqdn_recipient,reject_unknown_recipient_domain
檢查並重新啟動 postfix:
postfix check
systemctl restart postfix
您可以確保 postfix 現在正在偵聽連接埠 25 和 587:
netstat -na | grep LISTEN | grep 25
netstat -na | grep LISTEN | grep 587
不要忘記在防火牆中允許連接埠 587。
建立 postfix 使用者是另一回事。如評論中所提到的,您應該使用 SQL 來儲存郵箱(郵件使用者)。如果你不想這樣做,可以使用Linux用戶,詳細描述這裡。
PS 我認為在這裡提供完整的配置是不可行的,因為它總是非常依賴特定的案例要求和您的環境。
答案2
這將只允許安全連接:
smtpd_tls_auth_only = yes
然後你還有其他需要的選項:
smtpd_tls_security_level = may
smtp_sasl_auth_enable = yes
smtp_use_tls = yes
若要使用 587,請編輯 master.cf 並取消註解該行:
submission inet n - n - - smtpd
重啟後綴。