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

Unbound - domains cached only for short time

· 52CE 我爱测

I recently set up Unbound for DNS caching, along with DNScrypt on Linux Mint 18.1. It works, but I noticed the pages are cached only for short time: First query to google.com - 48ms (domain not cached) Second query to google.com …

问题原文

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

I recently set up Unbound for DNS caching, along with DNScrypt on Linux Mint 18.1. It works, but I noticed the pages are cached only for short time:

  1. First query to google.com - 48ms (domain not cached)
  2. Second query to google.com (immediately after that) - 0ms (domain cached)
  3. Third query to google.com (after ~ minute) - 46ms (domain not cached)

Is this intended behavior, or do I need to set something different to cache pages for longer time? Here is my Unbound config (/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

已采纳解答

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

Unbound will (or at least should) be caching the result for the time specified in the TTL for the record you are requesting.

This is exactly what I observe on a system I have to hand that is running unbound. The initial request takes 14ms, subsequent requests take 0ms and when the TTL expires the next request takes 14ms.

Initial request which shows a 300 second TTL and takes 18ms

;; 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

Subsequent requests - TTL is counting down and takes 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 expired so another upstream request is made 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

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

资料来源与适用范围

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

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

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