前言
Spamhaus 是电子邮件服务器中使用最广泛的远程黑名单(RBL)供应商, 特别是它提供的基于 DNS 的黑名单(DNSBLS)查询服务.
但是如果作为没有经验的人首次设置电子邮件服务器而去使用了 Spamhaus 的免费 DNSBLS, 比如在 Spamassassin 中配置了 zen.spamhaus.org
或者 sbl.spamhaus.org
, 就很有可能因为服务器的 DNS 设置导致得到错误的结果.
表现
Spamhaus 错误响应包括以下几种:
响应 | 释义 |
---|---|
127.255.255.252 | 查询请求发送到了错误的 DNSBL 列表. |
127.255.255.254 | 使用了公共 DNS 服务进行查询. |
127.255.255.255 | 查询次数过多. |
所以本文的话题就是表现为通过 Spamhaus 得到了 127.255.255.254
响应. 这本应该是作为一个错误而需要被抛出然后让程序捕获后处理, 但就现如今来说一些邮件服务器软件中的过滤组件或者 MTA 并不能很好处理这种情况. 对于这些软件, 出问题的逻辑基本就是: 如果查询得到了 NXDOMAIN
, 那么放行; 如果查询到了任何记录, 则直接阻止. 这些软件直接忽略了本应该需要处理的错误代码, 或者无法处理意外的响应. 而手动把这些入站 IP 拿去 Spamhaus 检测又检测不出任何问题, 任何入站 IP 都无法幸免.
演示
下面, 笔者将用一个 Gmail 的出站 IP 209.85.161.48
作为例子演示多个公共 DNS 服务查询结果.
为确保查询结果不受到网络影响将会使用加密 DNS.
服务商 | 结果 | 入口 |
---|---|---|
NXDOMAIN | https://dns.google/dns-query | |
Cloudflare | 48.161.85.209.zen.spamhaus.org. 2100 IN A 127.255.255.254 | https://dns.cloudflare.com/dns-query |
Cisco OpenDNS | NXDOMAIN | https://doh.opendns.com/dns-query |
Quad9 | 48.161.85.209.zen.spamhaus.org. 2100 IN A 127.255.255.254 | https://dns.quad9.net/dns-query |
AdGuard | 48.161.85.209.zen.spamhaus.org. 2087 IN A 127.255.255.255 | https://dns.adguard-dns.com/dns-query |
DNS.SB | NXDOMAIN | https://doh.dns.sb/dns-query |
Mullvad | NXDOMAIN | https://dns.mullvad.net/dns-query |
NextDNS | NXDOMAIN | https://dns.nextdns.io |
Wikimedia DNS | NXDOMAIN | https://wikimedia-dns.org/dns-query |
阿里云 | NXDOMAIN | https://dns.alidns.com/dns-query |
360 | NXDOMAIN | https://doh.360.cn/dns-query |
腾讯云 DNSPod | NXDOMAIN | https://doh.pub/dns-query |
以上包含了主流和非主流的大小公共 DNS 服务商, 可以看出已经有三个公共 DNS 解析服务出现了用作错误代码的 DNS 响应, AdGuard 的 DNS 甚至还是 127.255.255.255
响应. 这些响应还会出现在在线的 dig 或者 nslookup 工具中, 根据笔者的实际测试, 即使是相同的使用 Google 作为解析的在线工具, 查询出的结果也并不相同, 有的是 NXDOMAIN
, 有的就是 127.255.255.254
响应.
而受影响的邮件服务器如果无法处理错误, 那么就会导致发件方邮件被弹回, 发件人会收到包含以下内容或类似内容的邮件系统错误报告邮件:1
2
3
4
5
6
7Reporting-MTA: dns; mx.example.com
Action: failed
Final-Recipient: rfc822;inbound@example.org
Status: 5.0.0
Remote-MTA: dns; example.org
Diagnostic-Code: smtp; 554 5.7.1 Service unavailable; Client host [209.85.161.48] blocked using zen.spamhaus.org
或者 Exchange Online 的弹回错误响应:1
2
3
4
5
6
7
8
9
10Reporting-MTA: dns;****.apcprd03.prod.outlook.com
Received-From-MTA: dns;****.apcprd03.prod.outlook.com
Arrival-Date: Fri, 28 Feb 2025 12:43:39 +0000
Final-Recipient: rfc822;inbound@example.org
Action: failed
Status: 5.7.514
Diagnostic-Code: smtp;550 5.7.514 Decision Engine classified the mail item was rejected because of IP Block (from outbound normal IP pools) -> 554 5.7.1 Service unavailable; Client host [40.107.215.123] blocked using zen.spamhaus.org; Error: open resolver; https://check.spamhaus.org/returnc/pub/46.38.225.230/
Remote-MTA: dns;example.org
X-Display-Name: inbound@example.org
Exchange Online 的错误响应里面包含了最有效的信息: open resolver
.
原因
Spamhaus 的 DNSBLS 本质是使用 DNS 进行数据查询的 API. 它作为基础免费的服务在全球提供给小型的邮件服务器使用, 为了保持查询服务的正常运行, 需要对 DNS 查询操作的源头进行速率限制. 根据 Spamhaus 的描述, 由于一些公共 DNS 的策略, 导致 Spamhaus 无法确定来自这些 DNS 服务器的查询来自于哪里.
在对于全面禁止 Cloudflare DNS 查询的文章中, 它们提到:
The Spamhaus Project's Terms of Use state that it doesn't allow users to query via DNS resolvers where there is no attributable reverse DNS; this includes Cloudflare (we'll explain why later in this article).
Spamhaus 项目的使用条款规定, 它不允许用户通过没有可归属反向 DNS 的 DNS 解析器进行查询; 这包括 Cloudflare (我们将在本文后面解释原因).
[...]
Cloudflare masks organizations' queries to the Project's Public Mirrors, so the team can't attribute usage to individual entities. They have no way of establishing the number of queries a single organization is making.
Cloudflare 屏蔽了组织对项目公共镜像的查询, 因此(我们的)团队无法将使用情况归因于单个实体. 他们无法确定单个组织的查询次数.
根据最新的 Spamhaus 在 2025 年 1 月 8 日发布的文章, Hetzner 将会是下一个被屏蔽的, 从 2025 年 2 月 19 日开始将会缓慢实施这一屏蔽政策.
Hetzner 是非常有名的服务器托管商, 也有很多用户在上面设置自己的邮件服务器, 极有可能使用了包含 Spamhaus 的 DNSBLS 的服务器入站过滤软件, 可以预见将会影响位于 Hetzner 托管的邮件消息的传递性.
解决办法
作为邮件管理员, 遇到这种情况在确定原因是由公共 DNS 解析导致的, 并且仍然需要继续使用或者无法修改默认的行为是 Spamhaus 的 DNSBLS, 可以尝试以下的解决办法.
- 切换服务器 DNS 至未被屏蔽的解析服务器, 或直接使用托管商默认设置的内部 DNS 解析服务器.
- 使用 Spamhaus 的 DQS 服务: Sign up for a FREE Data Query Service Account - Spamhaus Technology
- 切换为可以正确处理错误的入站过滤组件, 然后设置其他后备 RBL.