大网数据广告活动
服务器运维问答

How long does dnsmasq cache dns?

· 52CE 我爱测

I looked up the man page and couldn't find how long dnsmasq cache a dns. what's the rule for caching and expiration? I am having a problem that request send to an external service sometimes takes over 5 or 10 seconds for namelook…

问题原文

原帖链接 · perlwle · CC BY-SA 3.0

I looked up the man page and couldn't find how long dnsmasq cache a dns. what's the rule for caching and expiration?

I am having a problem that request send to an external service sometimes takes over 5 or 10 seconds for namelookup. I could save the external service ip to /etc/hosts but I am afraid of ip change. Installing Dnsmasq improves name lookup but slow namelookup still happens with less frequency.

One solution is to setup a simple ping in cron job but I need to find out the expiration time first.

thanks.

UPDATE

added dig output

; <<>> DiG 9.8.1-P1 <<>> api.mch.weixin.qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45012
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;api.mch.weixin.qq.com.             IN      A

;; ANSWER SECTION:
api.mch.weixin.qq.com.      0       IN      A       140.207.69.102

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Jul 17 19:24:36 2015
;; MSG SIZE  rcvd: 55

UPDATE 2

the previous dig output contains TTL as 0 which is misleading. I have posted another dig output.

; <<>> DiG 9.8.1-P1 <<>> api.mch.weixin.qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60900
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;api.mch.weixin.qq.com.             IN      A

;; ANSWER SECTION:
api.mch.weixin.qq.com.      181     IN      CNAME   forward.qq.com.
forward.qq.com.             181     IN      A       101.226.90.149
forward.qq.com.             181     IN      A       101.226.129.200

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Jul 21 12:01:54 2015
;; MSG SIZE  rcvd: 99

社区高分解答

原帖链接 · Phizes · CC BY-SA 3.0

The option you will need to set for dnsmasq is --min-cache-ttl, the value is in seconds.

According to the dig output, the TTL is 0, if you set this to, say --min-cache-ttl=600, then the TTL value which will be returned by dig will be 600. The TTL for api.mch.weixin.qq.com from where I am is 600, so setting it to 600 seconds yourself should be reasonably safe in avoiding missing any IP changes. (I'm guessing you are located in China.)

This will cause all DNS records to be considered valid for 10 minutes.

See the dnsmasq mailing list message detailing the introduction of this feature.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-07-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。