将访问文件从 sendmail 转换为 postfix

将访问文件从 sendmail 转换为 postfix

我正在寻找将一个已有二十年历史、配置精良的 sendmail 安装(目前在 AlmaLinux 9 上运行)转换为 postfix 的方法。转换工作之一是将现有/etc/mail/access文件适配为/etc/postfix/access

有些语句看起来可以直接复制,但如果可以的话请确认这一点:

# by default we allow relaying from localhost...
Connect:127.0.0.1               RELAY

# Allow systems on our DMZ to use this server.
Connect:123.44.55               RELAY

# Allow systems on our NAT network to use this server as well.
Connect:10.44                   RELAY

# Accept mail sent to our  domain.
To:company.example.com          OK

# Forward any mail sent to our mailing-list server.
mailinglist.company.example.com     RELAY

# Reject commonly-used non-existent addresses
From:[email protected]   ERROR:5.7.1:550 Fake source address
From:[email protected]              ERROR:5.7.1:550 Fake source address
From:[email protected]            ERROR:5.7.1:550 Fake source address
From:[email protected]            ERROR:5.7.1:550 Fake source address

# 28-Nov-2005: Too much spam is being relayed by these guys, and bounced to us.
Connect:66.155.233.70               ERROR:5.7.1:550 Your mail server is a spam relay

# 09-Jun-2016: Uber-bad domain list. There are almost no servers in these domains that do
# not send spam. 
accountants                     ERROR:5.7.1:550 Domain used to send spam
bid                             ERROR:5.7.1:550 Domain used to send spam

# 09-Jun-2016: We've got a problem: When an unknown user receives
# email on our mail server, our mail server will reject mail
# to these users with "DSN: User unknown". This sounds fine, except
# that for aliases it sends a new email with that message back to the server
# that sent it. This results in "backscatter": our mail server starts
# sending mail from spammers back to bogus servers or forged
# addresses. The following is a list of user names completely retired
# from our mail server. It may not solve this problem, but it will
# hopefully reduce it. 

To:aaron@                    ERROR:550 No such user 
To:betsy@                    ERROR:550 No such user 

我遇到的困难:Sendmail 允许我根据每个系统或每个域设置邮件延迟和连接限制。我搜索了 postfix 文档,但不知道该怎么做。

具体来说,如果我在中包含以下语句/etc/mail/sendmail.mc

FEATURE(`greet_pause', `500')  dnl 
FEATURE(`ratecontrol', `nodelay', `terminate') dnl
define(`confCONNECTION_RATE_THROTTLE',`200') dnl
define(`confCONNECTION_RATE_WINDOW_SIZE',`60s') dnl
FEATURE(`conncontrol', `nodelay', `terminate') dnl

然后在中/etc/mail/access我可以包含如下语句:

GreetPause:batchmanager.company.example.com    400
GreetPause:company.example.com   0
GreetPause:mailinglist.company.example.com  0
GreetPause:127.0.0.1            0
GreetPause:friend.other.com     20
GreetPause:friendly.other.gov   20
GreetPause:10.44                0

ClientRate:123.44.55.66         6000    # mailinglist
ClientRate:123.44.55.77         60      # batchmanager
ClientRate:127.0.0.1            0
ClientRate:123.44.55            60

ClientConn:123.44.55.77         5       # batchmanager
ClientConn:123.44.55.66       500       # mailinglist

然后,远程站点的 TLS 配置似乎存在问题。或者可能是我们有问题,但只有这些站点选择检测并拒绝它。我通过以下方式解决了这个问题/etc/mail/access

Try_TLS:yetanother.different.com NO

我已经阅读了手册,但没有什么收获。关于如何在 Postfix 中实现这些功能,您有什么想法吗?

答案1

经过大量的研究,并且诅咒了所有告诉我 postfix 比 sendmail 更容易配置的人的命运之后,我想我已经找到了我自己的问题的答案。

请注意,我还没有机会测试这些限制是否有效。我已经实现了代码,没有错误消息,并且我的测试配置有效。但是,在将配置投入生产并且互联网的全部重量都压在服务器上之前,我无法完全测试反垃圾邮件代码。

简而言之:postfix 不支持将 sendmail 中的所有潜在语句/etc/mail/access放入单个文件中。相反,这些函数必须拆分成与 sendmail 相关联的不同文件。各种声明在后缀的中/etc/postfix/main.cf

另一个注意事项:我将大多数新的外部文件放入哈希表中。这主要是因为从后缀文档中不清楚是否可以在以下某些main.cf语句中使用纯文本文件,但哈希表始终可以。只要您看到下面的选项,例如hash:/etc/postfix/my-table,就意味着我创建/etc/postfix/my-table然后执行了:

postmap /etc/postfix/my-table
postfix reload

我不确定是否postfix reload总是需要这样做,但我选择谨慎行事。

继电器

在原文中/etc/mail/access,我有:

Connect:127.0.0.1                   RELAY
Connect:123.44.55                   RELAY
Connect:10.44                       RELAY
mailinglist.company.example.com     RELAY

在 中/etc/postfix/main.cf我输入:

mynetworks = 123.44.55.0/24, 127.0.0.0/8, 10.44.0.0/16
mydomain = company.example.com
mydestination = $myhostname,
       localhost.$mydomain,
       localhost,
       $mydomain,
       hash:/etc/postfix/local-host-names
smtpd_relay_restrictions =
  permit_mynetworks,
  permit_sasl_authenticated,
  reject_unauth_destination
relay_domains = $mydestination, hash:/etc/postfix/relay_recipients

在 中/etc/postfix/relay_recipients我输入:

mailinglist.company.example.com     RELAY

为了以防万一,我/etc/postfix/local-host-names为我们的邮件服务器设置了多个备用名称,这些名称均由我们的 DNS 记录中的 CNAME 定义:

mail.company.example.com
smtp.company.example.com

拒绝“发件人”地址

在我的原始access文件中,我有:

From:[email protected]   ERROR:5.7.1:550 Fake source address
From:[email protected]              ERROR:5.7.1:550 Fake source address
From:[email protected]            ERROR:5.7.1:550 Fake source address
From:[email protected]            ERROR:5.7.1:550 Fake source address

accountants                     ERROR:5.7.1:550 Domain used to send spam
bid                             ERROR:5.7.1:550 Domain used to send spam

在 中main.cf,我有:

smtpd_helo_restrictions = reject_unknown_helo_hostname,
  check_helo_access hash:/etc/postfix/from_restrictions

其中/etc/postfix/from_restrictions包含:

[email protected]   550 Fake source address typical of viruses
[email protected]              550 Fake source address typical of viruses
[email protected]            550 Fake source address typical of viruses
[email protected]            550 Fake source address typical of viruses

accountants                    550 Domain used to send spam
bid                            550 Domain used to send spam

拒绝 TLD 的/etc/mail/access行在 Postfix 中是否有效?postfix 访问手册页有点模棱两可。我看看会发生什么。

拒绝“收件人”地址

access有:

To:aaron@                    550 No such user 
To:betsy@                    550 No such user 

main.cf

smtpd_recipient_restrictions =
  permit_sasl_authenticated,
  permit_mynetworks,
  reject_unauth_destination,
  check_policy_service inet:127.0.0.1:10040,
  check_recipient_access hash:/etc/postfix/to_restrictions

包含etc/postfix/to_restrictions

aaron@                    550 No such user 
betsy@                    550 No such user 

check_policy_service与 postfwd 有关;我将在下面提到。

连接率和连接数

Postfix 不允许您为这些参数设置简单的每个 IP 或每个域的值,如下所示/etc/mail/access

ClientRate:123.44.55.66         6000    # mailinglist
ClientRate:123.44.55.77         60      # batchmanager
ClientRate:127.0.0.1            0
ClientRate:123.44.55            60

ClientConn:123.44.55.77         5       # batchmanager
ClientConn:123.44.55.66       500       # mailinglist

我所做的是为大多数连接设置总体限制,然后定义例外情况main.cf

anvil_rate_time_unit = 60s
smtpd_client_auth_rate_limit = 60
smtpd_client_connection_count_limit = 50
smtpd_client_connection_rate_limit = 100
smtpd_client_event_limit_exceptions =
   $mynetworks,
   4.56.78.0/24,   # friend.other.com
   5.67.89.0/24.   # friendly.other.gov

这很接近,但不是我想要的。特别是,batchmanager.company.example.com如果用户粗心地提交了一组作业,而每个作业都开始生成报告错误的电子邮件,那么我调用的机器可能会开始生成数千封电子邮件。使用 sendmail,我可以在邮件服务器上限制这种情况。我决定尝试使用后发

我最终留下的/etc/postfwd/postfwd.cf是:

id=RATE_UNKNOWN
   client_name==unknown
   action=rate(client_address/3/300/450 4.7.1 Deferred, max 3 requests in 5 mins from $$client_name at $$client_address)

id=THROTTLE_BATCH
   sender_localpart==batchmanager
   action=rate(client_address/20/60/450 4.7.1 Deferred, max 20 emails per minute from $$sender)

id=DEFAULT; action=DUNNO

这也限制了那些没有客户名称的垃圾邮件发送者,但这在当今并没有多大意义。

问候暂停

在 postfix 中没有与此直接等效的功能。我的不成熟的解决方案是为我不认识的系统引入延迟。在main.cf

smtpd_client_restrictions =
  permit_mynetworks,
  permit_sasl_authenticated,
  check_client_access hash:/etc/postfix/friendly_sites,
  reject_unknown_reverse_client_hostname,
  sleep 1,
  reject_unauth_pipelining

其中/etc/postfix/friendly_sites包含:

friend.other.com     OK
friendly.other.gov   OK

我感觉我可以使用以下方法引入可选的延迟后筛选,但我没找到办法。我在以下行中添加了以下行main.cf

postscreen_access_list = permit_mynetworks cidr:/etc/postfix/postscreen_access.cidr
postscreen_blacklist_action = drop
postscreen_greet_action = enforce

cidr:/etc/postfix/postscreen_access.cidr

123.44.55.66/32  permit    # mail server IP address

最好的情况是,这只能消除某些形式的垃圾邮件攻击,但不会造成任何延迟。

关闭某些网站的 TLS

正如我在评论中指出的那样,我可以在 postfix 中做到这一点。在其中/etc/mail/access我有以下行:

Try_TLS:yetanother.different.com   NO

在 中/etc/postfix/main.cf,我有:

smtp_tls_per_site = hash:/etc/postfix/tls_per_site

在 中/etc/postfix/tls_per_site,我有:

yetanother.different.com   NONE

包起来

我意识到我可能与上述某些操作中的反垃圾邮件功能重叠。我决定宁可安全也不要后悔。如果您发现我的转换存在任何问题,请告诉我。

相关内容