Postfix - 允许电子邮件发送至虚拟域但阻止垃圾邮件?

Postfix - 允许电子邮件发送至虚拟域但阻止垃圾邮件?

我的 Postfix 设置了虚拟域。这样人们就可以向 *@mydomain.com 发送电子邮件,然后该邮件将被转发到我的 gmail 帐户。基本上,最终目标只是允许人们发送电子邮件[电子邮件保护]并且它会被转发给我,这样我就不用拥有单独的邮箱了。

在我安装的几天里,它一直运行良好,直到今天早上我醒来时发现我的 postfix 发来了几千封中国垃圾邮件。他们使用别名,例如[电子邮件保护][电子邮件保护][电子邮件保护]将邮件发送到完全不相关的外部电子邮件地址。澄清一下,这是第三方利用我的服务器滥用垃圾邮件。

我立刻惊慌失措,开始查找问题所在。/etc/passwd 中没有新用户,而 /etc/shadow 中只有我的用户、FTP 和 root 用户(禁用了 SSH)可以登录。因此,这似乎是 Postix 配置错误。

我似乎已经通过添加修复了

smtpd_client_restrictions = permit_mynetworks, reject
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated 

# Block clients that speak too early.
smtpd_data_restrictions = reject_unauth_pipelining

# Enforce mail volume quota via policy service callouts.
smtpd_end_of_data_restrictions = check_policy_service unix:private/policy

到我的 main.cf。mail.log 仍然充满了所有这些尝试,但邮件不再被发送出去。示例

Aug  9 09:35:12 myusername postfix/smtpd[32085]: NOQUEUE: reject: RCPT from         unknown[183.147.82.118]: 554 5.7.1 <unknown[183.147.82.118]>: Client host rejected: Access denied; from=<eff@mydomain$
Aug  9 09:35:14 myusername postfix/smtpd[32085]: lost connection after DATA from unknown[183.147.82.118]
Aug  9 09:35:14 myusername postfix/smtpd[32085]: disconnect from unknown[183.147.82.118]

现在的问题是,当我尝试向我的任何域发送任何内容时,它会阻止合法的电子邮件。

554 5.7.1 <mail-ob0-f172.google.com[209.85.214.172]>: Client host rejected: Access denied

我可以做什么

A)允许任何电子邮件发送到我的虚拟域(例如[电子邮件保护]) 转发到我的 Gmail 帐户,但不允许垃圾邮件发送者以某种方式使用我的服务器发送垃圾邮件。

并且可选 B) 首先停止所有这些可能的尝试,并弄乱我的 mail.log

这是我的 main.cf

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mydomain1.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_domains = mydomain1.com, mydomain2.me
virtual_alias_maps = hash:/etc/postfix/virtual
myorigin = /etc/mailname
#mydestination = localhost.241.214.119, localhost
mydestination = $myhostname,localhost.$mydomain, localhost, $mydomain
#relayhost = mail.mydomain1.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_protocols = ipv4
milter_protocol = 2
milter_default_action = accept
smtpd_milters = inet:localhost:12301
non_smtpd_milters = inet:localhost:12301
smtp_generic_maps = hash:/etc/postfix/generic
smtpd_client_restrictions = permit_mynetworks, reject
    # Spam control: exclude local clients and authenticated clients
    # from DNSBL lookups.
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated 

    # Block clients that speak too early.
smtpd_data_restrictions = reject_unauth_pipelining

    # Enforce mail volume quota via policy service callouts.
smtpd_end_of_data_restrictions = check_policy_service unix:private/policy

和我的master.cf

#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       -       -       -       smtpd
#smtp      inet  n       -       -       -       1       postscreen
#smtpd     pass  -       -       -       -       -       smtpd
#dnsblog   unix  -       -       -       -       0       dnsblog
#tlsproxy  unix  -       -       -       -       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_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     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_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       -       -       -       qmqpd
pickup    unix  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
#qmgr     unix  n       -       n       300     1       oqmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -   n   n   -   2   pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

任何见解都值得赞赏!

答案1

听起来你基本上是在运行一个开放中继,过了一会儿,一些垃圾邮件机器人发现了它并开始通过它发送电子邮件。

有几个 Postfix 设置可以关闭您的服务器。一个是允许网络选项。我通常只允许本地“已知”网络,然后将任何其他网络范围添加到我需要的本地列表中。

另一个是要求对邮件中继进行身份验证。

看起来您现在可能已经完成上述两件事并阻止了垃圾邮件转发。

对于任何面向互联网的邮件服务器,我所做的另一件事(这取决于您可以使用哪些安全设备)是运行动态更新的防火墙规则,该规则从公开已知的阻止列表(例如 spamhaus top 100)中获取地址并将其添加到防火墙的阻止规则中。

我为此使用了 pfSense 和 pfBlockerNG,非常有效。

汤姆

相关内容