DNS 查询不使用 nscd 进行缓存

xen*_*ide 11 linux arch-linux cache dns

我正在尝试使用 nscd(Nameservices Cache Daemon)在本地缓存 DNS,这样我就可以停止使用 Bind 来做到这一点。我已经开始使用它并且 ntpd 似乎尝试使用它。但是主机的其他一切似乎都忽略了它。例如,如果我挖 apache.org 3 次,它们都不会命中缓存。我正在查看缓存统计信息nscd -g以确定它是否已被使用。我还提高了调试日志级别,看看我是否可以看到它命中并且查询甚至没有命中 nscd。

配置文件

# Begin /etc/nsswitch.conf
passwd: files
group: files
shadow: files

publickey: files

hosts: cache files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files
# End /etc/nsswitch.confenter code here
Run Code Online (Sandbox Code Playgroud)

配置文件

#
# /etc/nscd.conf
#
# An example Name Service Cache config file.  This file is needed by nscd.
#
# Legal entries are:
#
#       logfile                 <file>
#       debug-level             <level>
#       threads                 <initial #threads to use>
#       max-threads             <maximum #threads to use>
#       server-user             <user to run server as instead of root>
#               server-user is ignored if nscd is started with -S parameters
#       stat-user               <user who is allowed to request statistics>
#       reload-count            unlimited|<number>
#       paranoia                <yes|no>
#       restart-interval        <time in seconds>
#
#       enable-cache            <service> <yes|no>
#       positive-time-to-live   <service> <time in seconds>
#       negative-time-to-live   <service> <time in seconds>
#       suggested-size          <service> <prime number>
#       check-files             <service> <yes|no>
#       persistent              <service> <yes|no>
#       shared                  <service> <yes|no>
#       max-db-size             <service> <number bytes>
#       auto-propagate          <service> <yes|no>
#
# Currently supported cache names (services): passwd, group, hosts, services
#

    logfile                 /var/log/nscd.log
    threads                 4
    max-threads             32
    server-user             nobody
#   stat-user               somebody
    debug-level             9
#   reload-count            5
    paranoia                no
#   restart-interval        3600

    enable-cache            passwd          yes
    positive-time-to-live   passwd          600
    negative-time-to-live   passwd          20
    suggested-size          passwd          211
    check-files             passwd          yes
    persistent              passwd          yes
    shared                  passwd          yes
    max-db-size             passwd          33554432
    auto-propagate          passwd          yes

    enable-cache            group           yes
    positive-time-to-live   group           3600
    negative-time-to-live   group           60
    suggested-size          group           211
    check-files             group           yes
    persistent              group           yes
    shared                  group           yes
    max-db-size             group           33554432
    auto-propagate          group           yes

    enable-cache            hosts           yes
    positive-time-to-live   hosts           3600
    negative-time-to-live   hosts           20
    suggested-size          hosts           211
    check-files             hosts           yes
    persistent              hosts           yes
    shared                  hosts           yes
    max-db-size             hosts           33554432

    enable-cache            services        yes
    positive-time-to-live   services        28800
    negative-time-to-live   services        20
    suggested-size          services        211
    check-files             services        yes
    persistent              services        yes
    shared                  services        yes
    max-db-size             services        33554432
Run Code Online (Sandbox Code Playgroud)

配置文件

# Generated by dhcpcd from eth0
nameserver 127.0.0.1
domain westell.com
nameserver 192.168.1.1
nameserver 208.67.222.222
nameserver 208.67.220.220
Run Code Online (Sandbox Code Playgroud)

作为旁注,我正在使用 Arch Linux。

注意:这已经移动了两次,我一直不明白为什么应用程序,除了 dig,没有访问 nscd 缓存,浏览器,IM,IRC,都应该是,但他们没有

Res*_*ssu 15

缺少缓存命中的原因是 dig 直接查询 DNS。您可以尝试查看缓存是否适用于以下getent命令:

getent hosts host.example.com
Run Code Online (Sandbox Code Playgroud)

运行单独的缓存 DNS 是个好主意,但如果可能,您应该考虑在网络级别运行它。如果每个主机分别缓存数据,它们仍将对同一主机运行多个查询。单一缓存可以解决这个问题。

Nscd 本身是一个 NSS 函数的缓存守护进程。因此重点与本机缓存名称服务器略有不同。因此,如果您只想要一个缓存名称服务器,请使用 nscd 以外的其他东西。相反,如果您希望在普通 DNS 系统之外缓存共享用户名和主机数据等内容,请使用 nscd。

郑重声明,我非常喜欢 powerdns 解析器 (pdns-resolver)。

  • 其他软件确实应该访问 nscd 缓存。只要确保在启动 nscd 后重新启动软件。 (2认同)

Mar*_*ers 2

我对 nscd 不太了解,除了它经常导致 DNS 查找出现问题之外,我总是禁用它(或者至少禁用它的主机查找部分)。Nscd 允许您设置生存时间值,我知道 DNS 期望“拥有”这些值并让所有解析器尊重它们。如果不遵守 DNS 中的 TTL,您最终可能会得到奇怪的结果。我的建议是不要使用 nscd 来缓存 DNS。看起来您的本地机器上已经运行了一个缓存名称服务器,因此无需两次缓存 DNS 查找。