Postfix 长 DNS 查询

Postfix 长 DNS 查询

我使用我的 postfix 服务器作为另一个提供商的中继。我深入研究了一下,以找出为什么发送一封简单的邮件需要这么多时间。我发现 postfix 对每封邮件都进行了完整的 DNS 查询(浪费了 30 秒):

Apr 30 11:26:50 dev1 postfix/smtp[20917]: connecting to in.mailjet.com port 25
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_query: in.mailjet.com (MX): OK
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_get_answer: type MX for in.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_get_answer: type MX for in.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_get_answer: type MX for in.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_get_answer: type MX for in.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: dns_get_answer: type MX for in.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: smtp_addr_one: host smtp-ovhfr11.mailjet.com
Apr 30 11:26:55 dev1 postfix/smtp[20917]: lookup smtp-ovhfr11.mailjet.com type A flags 0
Apr 30 11:27:00 dev1 postfix/smtp[20917]: dns_query: smtp-ovhfr11.mailjet.com (A): OK
Apr 30 11:27:00 dev1 postfix/smtp[20917]: dns_get_answer: type A for smtp-ovhfr11.mailjet.com
Apr 30 11:27:00 dev1 postfix/smtp[20917]: smtp_addr_one: host smtp-ovhfr7.mailjet.com
Apr 30 11:27:00 dev1 postfix/smtp[20917]: lookup smtp-ovhfr7.mailjet.com type A flags 0
Apr 30 11:27:05 dev1 postfix/smtp[20917]: dns_query: smtp-ovhfr7.mailjet.com (A): OK
Apr 30 11:27:05 dev1 postfix/smtp[20917]: dns_get_answer: type A for smtp-ovhfr7.mailjet.com
Apr 30 11:27:05 dev1 postfix/smtp[20917]: smtp_addr_one: host smtp-ovhfr8.mailjet.com
Apr 30 11:27:05 dev1 postfix/smtp[20917]: lookup smtp-ovhfr8.mailjet.com type A flags 0
Apr 30 11:27:10 dev1 postfix/smtp[20917]: dns_query: smtp-ovhfr8.mailjet.com (A): OK
Apr 30 11:27:10 dev1 postfix/smtp[20917]: dns_get_answer: type A for smtp-ovhfr8.mailjet.com
Apr 30 11:27:10 dev1 postfix/smtp[20917]: smtp_addr_one: host smtp-ovhfr9.mailjet.com
Apr 30 11:27:10 dev1 postfix/smtp[20917]: lookup smtp-ovhfr9.mailjet.com type A flags 0
Apr 30 11:27:15 dev1 postfix/smtp[20917]: dns_query: smtp-ovhfr9.mailjet.com (A): OK
Apr 30 11:27:15 dev1 postfix/smtp[20917]: dns_get_answer: type A for smtp-ovhfr9.mailjet.com
Apr 30 11:27:15 dev1 postfix/smtp[20917]: smtp_addr_one: host smtp-ovhfr10.mailjet.com
Apr 30 11:27:15 dev1 postfix/smtp[20917]: lookup smtp-ovhfr10.mailjet.com type A flags 0
Apr 30 11:27:20 dev1 postfix/smtp[20917]: dns_query: smtp-ovhfr10.mailjet.com (A): OK
Apr 30 11:27:20 dev1 postfix/smtp[20917]: dns_get_answer: type A for smtp-ovhfr10.mailjet.com
Apr 30 11:27:20 dev1 postfix/smtp[20917]: begin in.mailjet.com address list
Apr 30 11:27:20 dev1 postfix/smtp[20917]: pref   10 host smtp-ovhfr11.mailjet.com/5.196.43.135
Apr 30 11:27:20 dev1 postfix/smtp[20917]: pref   10 host smtp-ovhfr7.mailjet.com/178.32.115.14
Apr 30 11:27:20 dev1 postfix/smtp[20917]: pref   10 host smtp-ovhfr8.mailjet.com/46.105.54.204
Apr 30 11:27:20 dev1 postfix/smtp[20917]: pref   10 host smtp-ovhfr9.mailjet.com/37.59.74.234
Apr 30 11:27:20 dev1 postfix/smtp[20917]: pref   10 host smtp-ovhfr10.mailjet.com/5.196.43.129
Apr 30 11:27:20 dev1 postfix/smtp[20917]: end in.mailjet.com address list
  • 为什么 Postfix 对每封邮件都发出这些请求?
  • 将 postfix 配置为使用具有 A DNS 条目的第一个可用 MX 是一个好主意吗? (以及我该如何实现?)
  • 有没有办法告诉 postfix 将所有这些 DNS 挖掘缓存至少一周?

答案1

  1. 您的主机似乎没有缓存 DNS 查找。它应该是。
  2. 您的操作系统(不是 postfix)应该缓存它需要的每个 DNS 记录查找。非传染性疾病是缓存“主机”查询的一个常用工具。

答案2

默认情况下,参数的值smtp_host_lookupdns。因此,postfix 将总是尝试解析 MX 记录接收者域以确定下一跳目的地。Postfix 依赖 libc 解析器进行查找,因此预期行为取决于库。例如,postfix 将始终通过 中定义的 NS 服务器进行查找/etc/resolv.conf

根据上面的日志,您的 NS 服务器似乎存在问题。单个 DNS 查找最多需要 5 秒钟才能返回结果,这是一种异常情况。以下是 Postfix 查找 MX 记录时的相同日志in.mailjet.com。它仅用 2 秒就完成了查找。

May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: in.mailjet.com (MX): OK
May  1 00:20:37 dewa postfix/smtp[4002]: dns_get_answer: type MX for in.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: message repeated 4 times: [ dns_get_answer: type MX for in.mailjet.com]
May  1 00:20:37 dewa postfix/smtp[4002]: smtp_addr_one: host smtp-ovhfr9.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr9.mailjet.com type A flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr9.mailjet.com (A): OK
May  1 00:20:37 dewa postfix/smtp[4002]: dns_get_answer: type A for smtp-ovhfr9.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr9.mailjet.com type AAAA flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr9.mailjet.com (AAAA): Host found but no data record of requested type
May  1 00:20:37 dewa postfix/smtp[4002]: smtp_addr_one: host smtp-ovhfr10.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr10.mailjet.com type A flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr10.mailjet.com (A): OK
May  1 00:20:37 dewa postfix/smtp[4002]: dns_get_answer: type A for smtp-ovhfr10.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr10.mailjet.com type AAAA flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr10.mailjet.com (AAAA): Host found but no data record of requested type
May  1 00:20:37 dewa postfix/smtp[4002]: smtp_addr_one: host smtp-ovhfr11.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr11.mailjet.com type A flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr11.mailjet.com (A): OK
May  1 00:20:37 dewa postfix/smtp[4002]: dns_get_answer: type A for smtp-ovhfr11.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr11.mailjet.com type AAAA flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr11.mailjet.com (AAAA): Host found but no data record of requested type
May  1 00:20:37 dewa postfix/smtp[4002]: smtp_addr_one: host smtp-ovhfr7.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr7.mailjet.com type A flags 0
May  1 00:20:37 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr7.mailjet.com (A): OK
May  1 00:20:37 dewa postfix/smtp[4002]: dns_get_answer: type A for smtp-ovhfr7.mailjet.com
May  1 00:20:37 dewa postfix/smtp[4002]: lookup smtp-ovhfr7.mailjet.com type AAAA flags 0
May  1 00:20:38 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr7.mailjet.com (AAAA): Host found but no data record of requested type
May  1 00:20:38 dewa postfix/smtp[4002]: smtp_addr_one: host smtp-ovhfr8.mailjet.com
May  1 00:20:38 dewa postfix/smtp[4002]: lookup smtp-ovhfr8.mailjet.com type A flags 0
May  1 00:20:38 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr8.mailjet.com (A): OK
May  1 00:20:38 dewa postfix/smtp[4002]: dns_get_answer: type A for smtp-ovhfr8.mailjet.com
May  1 00:20:38 dewa postfix/smtp[4002]: lookup smtp-ovhfr8.mailjet.com type AAAA flags 0
May  1 00:20:38 dewa postfix/smtp[4002]: dns_query: smtp-ovhfr8.mailjet.com (AAAA): Host found but no data record of requested type
May  1 00:20:38 dewa postfix/smtp[4002]: begin in.mailjet.com address list
May  1 00:20:38 dewa postfix/smtp[4002]: pref   10 host smtp-ovhfr9.mailjet.com/37.59.74.234
May  1 00:20:38 dewa postfix/smtp[4002]: pref   10 host smtp-ovhfr10.mailjet.com/5.196.43.129
May  1 00:20:38 dewa postfix/smtp[4002]: pref   10 host smtp-ovhfr11.mailjet.com/5.196.43.135
May  1 00:20:38 dewa postfix/smtp[4002]: pref   10 host smtp-ovhfr7.mailjet.com/178.32.115.14
May  1 00:20:38 dewa postfix/smtp[4002]: pref   10 host smtp-ovhfr8.mailjet.com/46.105.54.204

因此,从根源上解决问题的最佳方法是找出 NS 服务器为什么需要 5 秒钟来查找 DNS 条目。

仅使用 MX 记录的单一结果的解决方法在 Postfix 中不起作用。Postfix 将尝试解析所有域名的A记录返回自最好的偏好 MX 记录。MX 记录in.mailjet.com返回 5 个具有相同偏好的主机。因此,postfix 将从五个主机中查找 A 记录。

为了加快 DNS 查询速度,您可以使用 NSCD 并设置smtp_host_lookupnative(如 Andy 所建议)。另一种方法是运行本地 DNS 缓存,例如强力域名或者未绑定

相关内容