拒绝反向主机名解析失败的电子邮件

Min*_*ker 4 postfix spam

我的 Postfix 服务器正在从一组不断变化的域名接收垃圾邮件,但日志文件中的模式一致,以 line 开头warning: hostname X does not resolve to address Y。没有合法的(火腿)电子邮件具有此模式,因此我想阻止与此消息相关的电子邮件。

有没有办法在 Postfix 配置中完全阻止这些电子邮件,例如在 main.cf 文件中?

以下是日志文件的一部分,显示垃圾邮件到达时出现的模式:

May 10 21:47:46 localhost postfix/smtpd[313324]: warning: hostname trojan.kringeas.co.uk does not resolve to address 104.129.30.93: Name or service not known
May 10 21:47:46 localhost postfix/smtpd[313324]: connect from unknown[104.129.30.93]
May 10 21:47:46 localhost postfix/smtpd[313324]: 2AF1D101825: client=unknown[104.129.30.93]
May 10 21:47:46 localhost postfix/cleanup[313331]: 2AF1D101825: message-id=<dO7GXAfoNocg1hEkeyqMfulg7RZ0aamifKqrB8JpUH8.ofI9TFu7lSCnlxwicxT5GA@meansfolk.sa.com>
May 10 21:47:46 localhost postfix/qmgr[294981]: 2AF1D101825: from=<info@meansfolk.sa.com>, size=4241, nrcpt=1 (queue active)
May 10 21:47:46 localhost postfix/pipe[313333]: 2AF1D101825: to=<xx@xxxx.net>, orig_to=<hfew@xxxx.net>, relay=dovecot, delay=0.11, delays=0.08/0.01/0/0.02, dsn=2     .0.0, status=sent (delivered via dovecot service)
May 10 21:47:46 localhost postfix/qmgr[294981]: 2AF1D101825: removed
May 10 21:47:46 localhost postfix/smtpd[313324]: disconnect from unknown[104.129.30.93] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Run Code Online (Sandbox Code Playgroud)

这是我的 main.cf 文件: 请注意,它包括: smtpd_client_restrictions = reject_unknown_reverse_client_hostname我在阅读这篇文章后尝试过的。

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix/sbin
data_directory = /var/lib/postfix
mail_owner = postfix
inet_protocols = all
mydestination = localhost, localhost.localdomain
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
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

sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES


myhostname = xxxx.net
mynetworks = 127.0.0.0/8
message_size_limit = 30720000
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf, hash:/etc/postfix/virtual
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
smtpd_client_restrictions = reject_unknown_reverse_client_hostname
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem
smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem
virtual_create_maildirsize = yes
virtual_maildir_extended = yes
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
inet_interfaces = all
smtp_tls_security_level = may
disable_vrfy_command = yes
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept
Run Code Online (Sandbox Code Playgroud)

Nik*_*nov 8

只需更换

smtpd_client_restrictions = reject_unknown_reverse_client_hostname

smtpd_client_restrictions = reject_unknown_client_hostname

来自Postfix 手册

reject_unknown_client_hostname (with Postfix < 2.3: reject_unknown_client)
    Reject the request when 
      1) the client IP address->name mapping fails, or 
      2) the name->address mapping fails, or
      3) the name->address mapping does not match the client IP address.
    This is a stronger restriction than the reject_unknown_reverse_client_hostname 
    feature, which triggers only under condition 1) above.
    The unknown_client_reject_code parameter specifies the response code for
    rejected requests (default: 450). The reply is always 450 in case the
    address->name or name->address lookup failed due to a temporary problem. 
Run Code Online (Sandbox Code Playgroud)

然而,你的想法是错误的:

没有合法的(火腿)电子邮件具有此模式,因此我想阻止与此消息相关的电子邮件。

我的客户时不时地抱怨,有时反向主机名与 HELO 地址不符,或者解析为其他地址,或者根本不解析,这就是完美的征求邮件。基本上,当前的 RFC 仅强制要求HELO 主机名的 PTR 记录存在,而没有说明其值或该名称下的 A 记录或其值的存在。技术上合法的服务器可以忽略其他所有内容,并且仍然遵守 RFC,而您使用此配置来阻止它。为了解决这个问题,我将所有这些检查放入smtpd_recipient_restrictions, 并添加check_sender_access hash://...到它之前,这样我就可以通过发件人域名或完整的发件人电子邮件地址有选择地从该检查中排除一些邮件:

smtpd_client_restrictions = [default]
smtpd_recipient_restrictions = 
...
    check_sender_access hash:/etc/postfix/spam_exceptions,
    reject_unknown_client_hostname,
...
Run Code Online (Sandbox Code Playgroud)

您不能使用check_sender_accessin ,smtpd_client_restrictions因为您仅获取发件人信封地址以在阶段期间进行检查MAIL From:

spam_exceptions文件的结构很简单:

affected.domain OK
...
Run Code Online (Sandbox Code Playgroud)

当我解决投诉时,我只是将域添加到此文件中。我已经有相当多的收藏了!