V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
qsnow6
V2EX  ›  DNS

dnsmasq 缓存不生效

  •  
  •   qsnow6 · 2018-05-06 19:06:48 +08:00 · 6031 次点击
    这是一个创建于 2419 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 mac 上用 brew 安装好了 dnsmasq,经过一翻配置。折腾完了,但是测试后发现,并没有缓存成功。以下是 2 次 dig 日志

    
    deMacBook-Pro:etc $ dig g.cn
    
    ; <<>> DiG 9.10.6 <<>> g.cn
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27925
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ;; QUESTION SECTION:
    ;g.cn.				IN	A
    
    ;; ANSWER SECTION:
    g.cn.			129	IN	A	203.208.50.79
    g.cn.			129	IN	A	203.208.50.95
    g.cn.			129	IN	A	203.208.50.87
    g.cn.			129	IN	A	203.208.50.88
    
    ;; Query time: 103 msec
    ;; SERVER: 127.0.0.1#53(127.0.0.1)
    ;; WHEN: Sun May 06 19:01:04 CST 2018
    ;; MSG SIZE  rcvd: 97
    
    deMacBook-Pro:etc $ dig g.cn
    
    ; <<>> DiG 9.10.6 <<>> g.cn
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36864
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ;; QUESTION SECTION:
    ;g.cn.				IN	A
    
    ;; ANSWER SECTION:
    g.cn.			128	IN	A	203.208.50.88
    g.cn.			128	IN	A	203.208.50.79
    g.cn.			128	IN	A	203.208.50.95
    g.cn.			128	IN	A	203.208.50.87
    
    ;; Query time: 131 msec
    ;; SERVER: 127.0.0.1#53(127.0.0.1)
    ;; WHEN: Sun May 06 19:01:05 CST 2018
    ;; MSG SIZE  rcvd: 97
    
    

    dnsmasq.conf

    resolv-file=/usr/local/etc/resolv.dnsmasq.conf
    strict-order
    cache-size=32768
    listen-address=127.0.0.1
    zhangsihuideMacBook-Pro:etc zhangsihui$
    

    resolv.dnsmasq.conf

    deMacBook-Pro:etc $ cat resolv.dnsmasq.conf
    nameserver 61.139.2.69
    nameserver 202.98.96.68
    nameserver 119.29.29.29
    

    versions

    $ /usr/local/opt/dnsmasq/sbin/dnsmasq -v
    Dnsmasq version 2.79  Copyright (c) 2000-2018 Simon Kelley
    Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack no-ipset auth no-DNSSEC loop-detect no-inotify
    
    This software comes with ABSOLUTELY NO WARRANTY.
    Dnsmasq is free software, and you are welcome to redistribute it
    under the terms of the GNU General Public License, version 2 or 3.
    

    这是啥原因? dig 显示的 server 地址表示已经解析成功了,但是为什么没有缓存?

    10 条回复    2018-08-25 10:30:37 +08:00
    crysislinux
        1
    crysislinux  
       2018-05-06 19:09:42 +08:00 via Android
    生效了,129 变成 128 了
    qsnow6
        2
    qsnow6  
    OP
       2018-05-06 19:11:25 +08:00
    @crysislinux #1 不是看 Query time 吗
    crysislinux
        3
    crysislinux  
       2018-05-06 19:14:28 +08:00 via Android
    query time 确实不太好。但是那个时间感觉就是再算 ttl
    param
        4
    param  
       2018-05-07 02:58:01 +08:00 via Android
    我是緩存清不掉。。
    hzqim
        5
    hzqim  
       2018-05-07 10:25:13 +08:00
    设置 min-cache-ttl=3600

    效果:
    root@LEDE:~# dig www.baidu.com

    ; <<>> DiG 9.10.4-P5 <<>> www.baidu.com
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43889
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

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

    ;; ANSWER SECTION:
    www.baidu.com. 3459 IN CNAME www.a.shifen.com.
    www.a.shifen.com. 3459 IN A 14.215.177.38
    www.a.shifen.com. 3459 IN A 14.215.177.39

    ;; Query time: 1 msec
    ;; SERVER: 127.0.0.1#53(127.0.0.1)
    ;; WHEN: Mon May 07 10:21:00 CST 2018
    ;; MSG SIZE rcvd: 104
    krisbai
        6
    krisbai  
       2018-05-07 12:47:28 +08:00
    有没有开启客户端缓存服务?
    qsnow6
        7
    qsnow6  
    OP
       2018-05-08 22:29:23 +08:00
    @krisbai #6 这个配置是开启了吗

    resolv-file=/usr/local/etc/resolv.dnsmasq.conf
    strict-order
    cache-size=32768
    listen-address=127.0.0.1
    q0000x
        8
    q0000x  
       2018-05-16 09:10:35 +08:00   ❤️ 1
    @qsnow6 少了 min-cache-ttl=3600 这个配置,3600 是秒
    taobibi
        9
    taobibi  
       2018-05-24 09:27:24 +08:00
    @qsnow6 listen-address=0.0.0.0
    这样其他设备都能解析
    cache-size=32768
    min-cache-ttl=3600
    zhouyut001
        10
    zhouyut001  
       2018-08-25 10:30:37 +08:00
    用 all-servers,并发查询多个 dns,优选最快的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3526 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 73ms · UTC 00:51 · PVG 08:51 · LAX 16:51 · JFK 19:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.