如何减少 Sendmail DNS 超时时间

如何减少 Sendmail DNS 超时时间

我对发送邮件尝试发送到存在 DNS 问题的电子邮件地址时的 DNS 超时期限。假设有问题的电子邮件地址是[电子邮件保护]

我可以使用以下方法查看该域名的 DNS 问题:

>host -t mx example.com
;; connection timed out; no servers could be reached

我可以使用以下命令测试并计时对有问题的电子邮件地址的 sendmail 调用:

> time echo "This is a test message" | /usr/lib/sendmail [email protected] [email protected]
real 2m36.252s
user 0m0.004s
sys  0m0.005s

目前,sendmail 超时需要 2 分 36 秒!这导致我们尝试发送到该电子邮件地址的 PHP 网页挂起,并最终向浏览器返回错误。

我的问题是:如何减少这个超时?

我见过几个与sendmail相关的超时配置:

> grep resolver /etc/mail/sendmail.cf
Timeout.resolver.retrans=5s
Timeout.resolver.retry=4

Sendmail 似乎设置为重试 4 次,每次重新传输都有 5 秒的延迟。

但我没有找到实际的DNS超时时间?

供参考:这发生在 Red Hat Enterprise Linux Server 版本 5.2、sendmail 8.13.8、Linux 内核:2.6.18、Apache 版本:2.2.3、PHP 版本:5.3.0 上笔记:这个问题是某些电子邮件地址的 Sendmail 出现延迟

答案1

作为一种快速解决方法,您可以修改 /etc/resolv.conf。当然,这会改变系统解析器的工作方式,这根本不是 sendmail 特有的问题。

timeout: n
    sets the amount of time the resolver will wait for a response from a remote name server before retrying the query via a different name server. Measured in seconds, the default is RES_TIMEOUT (see <resolv.h> ). 
attempts: n
    sets the number of times the resolver will send a query to its name servers before giving up and returning an error to the calling application. The default is RES_DFLRETRY (see <resolv.h> ). 

从长远来看,上述方法并不是一个好的解决方案。您的 DNS 服务器设置已损坏,需要修复。如果有关于不存在的 MX/域的查询,服务器应该快速响应 NXDOMAIN。它不应该等待这么长时间,因为它通常会导致许多程序出现各种问题(首先是 sendmail,但通常还有 sshd 和 NFS)。

相关内容