Domain-Name-System

如何減少 Sendmail DNS 超時時間

  • March 28, 2015

嘗試發送到有 DNS 問題的電子郵件地址時,我遇到了*sendmail DNS 超時期限的問題。*假設有問題的電子郵件地址是test@example.com

我可以使用以下方法看到此域存在 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 -ftest@test.com test@example.com
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 延遲的跟進

作為一種快速解決方法,您可以修改 /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)。

引用自:https://serverfault.com/questions/92603