DNS 查詢不使用 nscd 進行快取

DNS 查詢不使用 nscd 進行快取

我正在嘗試使用 nscd(名稱服務快取守護程序)在本地快取 DNS,以便我可以停止使用 Bind 來執行此操作。我已經啟動了它,並且 ntpd 似乎嘗試使用它。但對於主人來說,其他一切似乎都忽略了它。例如,如果我挖掘 apache.org 3 次,它們都不會命中快取。我正在查看快取統計資料以nscd -g確定它是否已被使用。我還調高了調試日誌級別,看看是否可以看到它命中,並且查詢甚至沒有命中 nscd。

nsswitch.conf

# 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

nscd.conf

#
# /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

解析設定檔

# 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

順便說一句,我正在使用 Arch Linux。

注意:這已經被移動了兩次,我從來沒有弄清楚為什麼應用程式(不包括 dig)沒有命中 nscd 緩存,瀏覽器,IM,IRC,所有這些都應該是,但他們沒有

答案1

錯過快取命中的原因是 dig 直接查詢 DNS。您可以嘗試使用以下命令查看快取是否有效getent

getent hosts host.example.com

運行單獨的快取 DNS 是一個好主意,但如果可能的話,您應該考慮在網路層級運行它。如果每個主機單獨快取數據,它們仍然會對同一主機執行多個查詢。單一快取可以解決這個問題。

Nscd 本身就是 NSS 功能的快取守護程式。因此,焦點與本機快取名稱伺服器有點不同。因此,如果您只想要一個快取名稱伺服器,請使用 nscd 以外的其他東西。相反,如果您希望在正常 DNS 系統之外快取共享使用者名稱和主機資料等內容,請使用 nscd。

鄭重聲明,我非常喜歡 powerdns 解析器 (pdns-resolver)。

答案2

您缺少 nscd.conf 中的主機配置。我以我的為例:

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

這會破壞一些東西。以下資訊來自 Debian 軟體包:

  Since this release, hosts caching in nscd is off by default: for some of the
  libc calls (gethostby* calls) nscd does not respect the DNS TTLs.  It can
  lead to system lockups (e.g. if you are using pam-ldap and change the IP of
  your authentication server) hence is not considered safe.

  See debian bug #335476 and how upstream answered to that in
  http://sourceware.org/bugzilla/show_bug.cgi?id=4428.

 -- Pierre Habouzit <[email protected]>  Sat, 28 Apr 2007 11:10:56 +0200

答案3

我對 nscd 不太了解,除了它經常導致 DNS 查找出現問題之外,我總是停用它(或至少停用它的主機查找部分)。 Nscd 允許您設定生存時間值,我知道 DNS 期望「擁有」這些值並讓所有解析器尊重它們。如果不遵守 DNS 中的 TTL,您最終可能會得到奇怪的結果。我的建議是不要使用 nscd 來快取 DNS。看起來您的本機上已經運行了一個快取名稱伺服器,因此無需兩次快取 DNS 查找。

答案4

如果地獄裡有DNS快取的話,那是nscd提供的。不。使用。它。

只是為了與眾不同:資料中心實際上是一個非常好的替代品。或 unscd (至少在 openSUSE 中預設使用)。

相關內容