为什么 TTL 有时会在 DNS 查询之间重新增加?

为什么 TTL 有时会在 DNS 查询之间重新增加?

dig xkcd.com得到了类似这样的结果:

; <<>> DiG 9.9.5-3ubuntu0.1-Ubuntu <<>> xkcd.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52538
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 5

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;xkcd.com.          IN  A

;; ANSWER SECTION:
xkcd.com.       769 IN  A   107.6.106.82

;; AUTHORITY SECTION:
xkcd.com.       87784   IN  NS  dns3.p03.nsone.net.
xkcd.com.       87784   IN  NS  dns1.p03.nsone.net.
xkcd.com.       87784   IN  NS  dns2.p03.nsone.net.
xkcd.com.       87784   IN  NS  dns4.p03.nsone.net.

;; ADDITIONAL SECTION:
dns1.p03.nsone.net. 70809   IN  A   198.51.44.3
dns2.p03.nsone.net. 70809   IN  A   198.51.45.3
dns3.p03.nsone.net. 71406   IN  A   198.51.44.67
dns4.p03.nsone.net. 70809   IN  A   198.51.45.67

;; Query time: 222 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Jan 21 22:16:42 HKT 2015
;; MSG SIZE  rcvd: 206

这是的769缓存值。但是,当我重复几次(间隔几秒钟)时,每次都会得到一个看似随机的值。以下是序列:TTLxkcd.comdig xkcd.comTTL

TRY | ANSWER | AUTHORITY | ADDITIONAL | WHEN
====================================================================
1   | 586    | 59577     | 44474      | Wed Jan 21 22:18:31 HKT 2015
2   | 587    | 14242     | 56745      | Wed Jan 21 22:18:32 HKT 2015
3   | 658    | 87673     | 70698      | Wed Jan 21 22:18:34 HKT 2015
4   | 1022   | 76200     | 51189      | Wed Jan 21 22:18:40 HKT 2015
5   | 1200   | 160954    | 44662      | Wed Jan 21 22:18:41 HKT 2015
6   | 574    | 59565     | 44462      | Wed Jan 21 22:18:43 HKT 2015
7   | 646    | 87661     | 70686      | Wed Jan 21 22:18:46 HKT 2015
8   | 1200   | 121364    | 55967      | Wed Jan 21 22:18:47 HKT 2015
9   | 1200   | 83292     | 54698      | Wed Jan 21 22:18:48 HKT 2015
10  | 1024   | 40540     | 43816      | Wed Jan 21 22:18:49 HKT 2015

为什么我会得到这个看似随机(在一定范围内)的值TTL?我预计它会逐渐减少,因为它被缓存了。

答案1

Dig 报告称TTL 到期前的剩余时间而不是实际的 TTL 值。如果数字不同,则很可能您正在查询不同的 DNS 服务器(例如,循环),这些服务器缓存记录的时间不同,因此到期时间也不同。

如果您对同一 DNS 服务器运行相同的查询,您将看到 TTL 减少的秒数(大致)与您在查询之间等待的秒数相同。如下所示:

ragnarok:~ cwatson$ dig a cwatson.org @192.168.50.11; sleep 2s; dig a cwatson.org @192.168.50.11

; <<>> DiG 9.8.3-P1 <<>> a cwatson.org @192.168.50.11
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39178
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;cwatson.org.           IN  A

;; ANSWER SECTION:
cwatson.org.        5847    IN  A   46.249.223.150

;; Query time: 43 msec
;; SERVER: 192.168.50.11#53(192.168.50.11)
;; WHEN: Wed Jan 21 14:51:08 2015
;; MSG SIZE  rcvd: 45


; <<>> DiG 9.8.3-P1 <<>> a cwatson.org @192.168.50.11
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24943
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;cwatson.org.           IN  A

;; ANSWER SECTION:
cwatson.org.        5845    IN  A   46.249.223.150

;; Query time: 45 msec
;; SERVER: 192.168.50.11#53(192.168.50.11)
;; WHEN: Wed Jan 21 14:51:10 2015
;; MSG SIZE  rcvd: 45

因此,对于您的完整示例,距离 A 记录过期还有 769 秒,这将强制从上游 DNS 服务器重新查找。

查看答案这里了解更多详情。

相关内容