在一个 SPF a:name 中使用多个 A 记录

在一个 SPF a:name 中使用多个 A 记录

假设我的 SPF 记录如下所示:

v=spf1 a:spf.example.com -all

记录spf.example.com如下:

spf.example.com A 12.12.12.12
spf.example.com A 12.42.66.12
spf.example.com A 12.16.48.12
spf.example.com A 12.73.23.12
spf.example.com AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:1001
spf.example.com AAAA 2001:0db8:85a3:0000:0000:5a1e:1288:1001
spf.example.com AAAA 2001:0db8:85a3:0000:0000:3b2e:5241:1001
spf.example.com AAAA 2001:0db8:85a3:0000:0000:2f2e:8361:1001

所有这些 IP 地址都会通过 SPF 验证吗?如果是这样,一个名称的 A 记录数量是否有限制?在我看来,像 Google 或 Outlook 这样的大型提供商都没有使用这种方法。这是因为这是一种不好的做法吗?

我问这个问题的原因:我认为这种方法比使用多个包含更好,因为 SPF 记录的 DNS 查找限制为 10 个。使用这种方法只需要 1 个 DNS 查找,所以我猜它会加快速度,而且你永远不会达到 SPF 的 TXT 记录中的 255 个字符限制。

答案1

当您a在 SPF 中使用机制时,这意味着通过查找找到的所有与客户端使用的地址系列相对应的地址都将匹配。即,如果客户端通过 IPv4 连接,则A进行查找;如果客户端通过 IPv6 连接,则AAAA进行查找。

从一般的 DNS 角度来看,单个名称的记录数量限制并不是一个固定的数字,而是发送响应时整体消息大小的限制。你真的不能把这个限制拉得太长。

可能存在一些折衷方案,您所描述的方法可以作为有用的技巧,但如果您看看大型提供商,他们通常拥有用于其服务的大量地址池。他们指定地址前缀(可能使用 SPFip4ip6机制)而不是执行涉及列出单个地址的任何操作(如AAAAA记录,这是a机制将导致的),很快就会节省更多。

如果我们看一下您提到的一个例子,即谷歌,我们会看到:

_spf.google.com.        300     IN      TXT     "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"

_netblocks.google.com.  3600    IN      TXT     "v=spf1 ip4:35.190.247.0/24 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:108.177.8.0/21 ip4:173.194.0.0/16 ip4:209.85.128.0/17 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ~all"

_netblocks2.google.com. 3600    IN      TXT     "v=spf1 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"

_netblocks3.google.com. 3600    IN      TXT     "v=spf1 ip4:172.217.0.0/19 ip4:172.217.32.0/20 ip4:172.217.128.0/19 ip4:172.217.160.0/20 ip4:172.217.192.0/19 ip4:108.177.96.0/19 ip4:35.191.0.0/16 ip4:130.211.0.0/22 ~all"

这意味着,对于典型的用户域,需要进行四次查找才能指定:

  • 256 + 8192 + 4096 + 4096 + 16384 + 65536 + 2048 + 65536 + 32768 + 8192 + 8192 + 4096 + 8192 + 4096 + 8192 + 8192 + 65536 + 1024 =314624 IPv4 地址
  • 4951760157141521099596496896 + 4951760157141521099596496896 + 4951760157141521099596496896 + 4951760157141521099596496896 + 4951760157141521099596496896 + 4951760157141521099596496896 =29710560942849126597578981376IPv6 地址

相关内容