Dnsmasq 的 DNS 响应自动缓存功能不起作用

Dnsmasq 的 DNS 响应自动缓存功能不起作用

Dnsmasq 缓存和 USR1 信号转储上的内部日志(运行时无论是否使用 --no-daemon 和 --log-queries 进行分析)始终显示:0/0 缓存,这意味着 Dnsmasq 的缓存功能不起作用。

还观察到,虽然重复的 DNS A?(主机查询)和 A(响应)记录通过相同的监听接口连续成功填充,但缓存计数仍然保持为 0。

有人知道如何解决/调试这个 Dnsmasq Cache 不工作问题吗?

或者,请建议另一个可针对目标接口进行配置的 Ubuntu Linux 支持的 DNS 缓存工具。

dnsmasq:缓存大小 150,0/0 缓存插入重新使用未过期的缓存条目

root@host1:~# sudo pkill -USR1 dnsmasq
dnsmasq: query[AAAA] host1 from 127.0.0.1
dnsmasq: query[AAAA] host1 from 127.0.0.1
dnsmasq: query[A] host1 from 127.0.0.1
dnsmasq: query[A] host1 from 127.0.0.1
sudo: unable to resolve host host1
dnsmasq: time 1432979095
dnsmasq: cache size 150, 0/0 cache insertions re-used unexpired cache entries.
dnsmasq: queries forwarded 0, queries answered locally 4
dnsmasq: Host Address Flags Expires
dnsmasq: ip6-loopback ::1 6F I H 
dnsmasq: pep 127.0.1.1 4FRI H 
dnsmasq: ip6-mcastprefix ff00:: 6FRI H 
dnsmasq: ip6-allrouters ff02::2 6FRI H 
dnsmasq: ip6-localhost ::1 6FRI H 
dnsmasq: localhost 127.0.0.1 4FRI H 
dnsmasq: ip6-allnodes ff02::1 6FRI H 
dnsmasq: ip6-localnet fe00:: 6FRI H 
[1]- User defined signal 1 /etc/init.d/dnsmasq restart
root@host1:~#

TCPDUMP ON DNSMASQ Interface:

05:40:47.555213 IP 172.20.20.10.52592 > 172.20.20.2.53: 8856+ A? app.host2.com. (45)
05:40:47.558364 IP 172.20.20.2.53 > 172.20.20.10.52592: 8856* 1/0/0 A 10.60.60.190 (61)
05:41:52.875128 IP 172.20.20.10.60448 > 172.20.20.2.53: 11981+ A? app.host2.com. (45)
05:41:52.878377 IP 172.20.20.2.53 > 172.20.20.10.60448: 11981* 1/0/0 A 10.60.60.190 (61)
05:42:44.241724 IP 172.20.20.10.65300 > 172.20.20.2.53: 6667+ A? app.host2.com. (45)
05:42:44.244808 IP 172.20.20.2.53 > 172.20.20.10.65300: 6667* 1/0/0 A 10.60.60.190 (61)

Dnsmasq setting: /etc/dnsmasq.conf

log-facility=/var/log/dnsmasq.log
log-queries
log-dhcp
no-daemon
listen-address=10.20.20.15
port=53
interface=eth0
bind-interfaces
cache-size=1000
neg-ttl=3600

Dnsmasq Running as inline from default:

root@host1:~# /etc/init.d/dnsmasq restart
* Restarting DNS forwarder and DHCP server dnsmasq                                                                                   
dnsmasq: started, version 2.68 cachesize 1000
dnsmasq: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP 
DHCPv6 no-Lua TFTP conntrack ipset auth
dnsmasq: reading /etc/resolv.conf
dnsmasq: using nameserver 11.45.45.9#53
dnsmasq: read /etc/hosts - 7 addresses
User defined signal 1
root@host1:~# dnsmasq: time 1433019086
dnsmasq: cache size 1000, 0/0 cache insertions re-used unexpired cache 
entries.
dnsmasq: queries forwarded 0, queries answered locally 0
dnsmasq: queries for authoritative zones 0
dnsmasq: Host                                     Address                           
Flags     Expires
dnsmasq: ip6-allnodes                             ff02::1                        
6FRI   H   
dnsmasq: ip6-localnet                             fe00::                         
6FRI   H   
dnsmasq: ip6-localhost                            ::1                            
6FRI   H   
dnsmasq: pep                                      127.0.1.1                      
4FRI   H   
dnsmasq: ip6-mcastprefix                          ff00::                         
6FRI   H   
dnsmasq: localhost                                127.0.0.1                      
4FRI   H   
dnsmasq: ip6-loopback                             ::1                            
6F I   H   
dnsmasq: ip6-allrouters                           ff02::2                        
6FRI   H   

Dnsmasq process status:

root@host1:~# ps aux | grep dnsmasq
dnsmasq  23437  0.0  0.0  27636   936 ?        S    16:36   0:00  
/usr/sbin/dnsmasq -x /var/run/dnsmasq/dnsmasq.pid -u dnsmasq 
-r /var/run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-
old,.dpkg-new

Dnsmasq package status:

root@host1:~# dpkg -l | grep dnsmasq
ii  dnsmasq                                               2.68-1                                              all          Small caching DNS  
     proxy and DHCP/TFTP server
ii  dnsmasq-base                                          2.68-1       
                                  amd64        Small caching DNS proxy 
                                              and DHCP/TFTP server
ii  dnsmasq-utils                                         2.68-1       

                                     

答案1

我也遇到了这个问题,并且找到了我认为的根本原因。

请捕获您的 DNS 回复的 wireshark 转储,并检查“递归可用”字段是否设置为“服务器可以执行递归查询”,如果未设置,则这些响应将不会添加到缓存中。

答案2

我遇到了同样的问题。删除listen-addressin favor 为interface我解决了这个问题 - 这实际上看起来像是 dnsmasq 中的一个错误。

关于阿伦的回答,对我来说可以使用递归。

小测试脚本:

sudo kill -usr1 $(pidof dnsmasq) for ((n=0;n<100;n++)); do dig @127.0.0.1 google.com; done sudo kill -usr1 $(pidof dnsmasq) tail /var/log/syslog

相关内容