我最近在 Linux Mint 18.1 上设置了 Unbound 进行 DNS 缓存,以及 DNScrypt。它可以工作,但我注意到页面只能缓存很短的时间:
- 第一次查询 google.com - 48ms(域名未缓存)
- 第二次对 google.com 的查询(紧接着)-0ms(域名缓存)
- 第三次查询 google.com(约一分钟后) - 46ms(域名未缓存)
这是预期的行为吗?还是我需要设置其他内容来将页面缓存更长时间?这是我的 Unbound 配置 (/etc/unbound/unbound.conf):#
Unbound configuration file for Debian.
#
# See the unbound.conf(5) man page.
#
# See /usr/share/doc/unbound/examples/unbound.conf for a commented
# reference config file.age
#
# The following line includes additional configuration files from the
# /etc/unbound/unbound.conf.d directory.
include: "/etc/unbound/unbound.conf.d/*.conf"
server:
verbosity: 1
num-threads: 4
outgoing-range: 8192
so-rcvbuf: 4m
so-sndbuf: 4m
so-reuseport: yes
msg-cache-size: 50m
msg-cache-slabs: 16
num-queries-per-thread: 4096
rrset-cache-size: 100m
rrset-cache-slabs: 16
infra-cache-slabs: 16
do-ip4: yes
do-ip6: no
do-udp: yes
do-tcp: yes
do-daemonize: yes
hide-identity: yes
hide-version: yes
harden-short-bufsize: yes
harden-large-queries: yes
harden-glue: yes
harden-dnssec-stripped: yes
harden-below-nxdomain: yes
harden-referral-path: yes
logfile: "/etc/unbound/unbound.log"
use-caps-for-id: yes
do-not-query-localhost: no
prefetch: no
forward-zone:
name: "."
forward-addr: 127.0.0.1@40
答案1
Unbound 将(或至少应该)在指定的时间内缓存结果生存时间以供您请求的记录。
这正是我在手头上观察到的无限制运行系统的情况。初始请求需要 14 毫秒,后续请求需要 0 毫秒,当 TTL 到期时,下一个请求需要 14 毫秒。
初始请求显示 300 秒 TTL 并耗时 18 毫秒
;; ANSWER SECTION:
google.com. 300 IN A 172.217.20.46
;; Query time: 18 msec
;; SERVER: 10.34.20.1#53(10.34.20.1)
;; WHEN: Sun Feb 12 20:39:30 2017
;; MSG SIZE rcvd: 44
后续请求 - TTL 正在倒计时,耗时 0ms
;; ANSWER SECTION:
google.com. 196 IN A 172.217.20.46
;; Query time: 0 msec
;; SERVER: 10.34.20.1#53(10.34.20.1)
;; WHEN: Sun Feb 12 20:41:14 2017
;; MSG SIZE rcvd: 44
TTL 已过期,因此在 23ms 时发出另一个上行请求
;; ANSWER SECTION:
google.com. 300 IN A 172.217.20.46
;; Query time: 23 msec
;; SERVER: 10.34.20.1#53(10.34.20.1)
;; WHEN: Sun Feb 12 20:44:37 2017
;; MSG SIZE rcvd: 44
答案2
我来晚了,但据我了解,如果你想要“几乎总是缓存”,你应该启用该prefetch
选项。
prefetch: <yes or no>
If yes, message cache elements are prefetched before they expire
to keep the cache up to date. Default is no. Turning it on
gives about 10 percent more traffic and load on the machine, but
popular items do not expire from the cache.