如何衡量 DNS 缓存效率/缓存项目?

如何衡量 DNS 缓存效率/缓存项目?

我已dnsmasq在 Debian 服务器上配置为仅缓存 DNS 服务器,并且运行良好(我通过 dig 看到 DNS 响应时间有所改善)。

但是,我想dnsmasq随时了解什么是缓存,以便我可以开始考虑我所实现的效率(即命中率)。

我浏览了手册页和网页,但找不到如何查看dnsmasq缓存的内容(例如,与您对租约所做的不同,租约保存在 dnsmasq.lease 文件中)。

DNSdnsmasq缓存仅保存在内存中吗?或者我必须做一些日志文件修改吗?

答案1

我无权访问,dnsmasq但根据标题为:dnsmasq 是缓存吗?您可以向进程发送信号 USR1 dnsmasq,使其将统计信息转储到系统日志中。

$ sudo pkill -USR1 dnsmasq

然后查看系统日志:

$ sudo tail /var/log/syslog
Jan 21 13:37:57 dnsmasq[29469]: time 1232566677
Jan 21 13:37:57 dnsmasq[29469]: cache size 150, 0/475 cache insertions re-used unexpired cache entries.
Jan 21 13:37:57 dnsmasq[29469]: queries forwarded 392, queries answered locally 16
Jan 21 13:37:57 dnsmasq[29469]: server 208.67.222.222#53: queries sent 206, retried or failed 12
Jan 21 13:37:57 dnsmasq[29469]: server 208.67.220.220#53: queries sent 210, retried or failed 6

笔记:我相信它将dnsmasq缓存保留在 RAM 中。

因此,如果您想转储缓存,则需要在调用-q时启用该开关。手册页dnsmasq中提到了这一点dnsmasq

   -d, --no-daemon
        Debug mode: don't fork to the background, don't write a pid file, 
        don't change user id, generate a complete cache dump  on
        receipt on SIGUSR1, log to stderr as well as syslog, don't fork new 
        processes to handle TCP queries. Note that this option is for use in 
        debugging only, to stop dnsmasq daemonising in production, use -k.

   -q, --log-queries
        Log the results of DNS queries handled by dnsmasq. Enable a full 
        cache dump on receipt of SIGUSR1.

答案2

从手册页获取此信息的另一种方法:

缓存统计信息也可在 DNS 中用作域绑定中 CHAOS 类和 TXT 类型查询的答案。域名为cachesize.bind、insertions.bind、evictions.bind、misses.bind、hits.bind、auth.bind 和servers.bind。使用 dig 实用程序查询此命令的示例命令是

   dig +short chaos txt cachesize.bind
   dig +short chaos txt hits.bind
   dig +short chaos txt misses.bind

如果您的系统上有类似 systemd-resolve 的东西,那么您需要直接使用以下命令查询服务器:

   dig +short chaos txt hits.bind @serverIP

相关内容