Dynamic DNS-Caching with PDNSd and DHCP
(I write this in English because I was asked to do so by some people on the Arch forums. Anyway, I think this should be no problem as if you hack on configs you normally understand enough to get this done as well.)
I've been using pdnsd for DNS caching for quite a while now and I can feel the speed up while browsing the web (at least I can go on believing so
) or checking for updates in the AUR.
The problem with pdnsd in conjunction with mobile devices (like the netbook I'm typing this on) is that in the basic setup, it only uses static DNS servers, described in /etc/pdnsd.conf. So if you happen to get behind some firewall that doesn't permit DNS queries to other nameservers than the ones advertised by DHCP, you have to change your setup manually - and switch back when you're out.
It would be great if pdnsd took the DNS your machine got from DHCP and use it as primary source for cache-misses. This also uses the eventually existing DNS infrastructure and local caches, instead of bypassing them. Here's how I implemented that, using pdnsd and dhcpcd:
- Setup pdnsd as described in the Arch Wiki article, but do not create a
/etc/resolv.conf.head. Create a primary DNS source entry, mine looks like this:server { label="maindns"; ip=8.8.8.8, 8.8.8.4; # I use Google dns as fallback proxy_only=on; # Do not query any other name servers timeout=4; # Server timeout uptest=none; # No uptest purge_cache=off; # Keep stale cache entries in case the ISP's # DNS servers go offline. }
- In
/etc/resolv.conf, the only nameserver should be your local machine:# /etc/resolv.conf nameserver 127.0.0.1
- In
/etc/dhcpcd.conf, disable the resolv.conf-hook to prevent dhcpcd from changing the resolving scheme:[...] nohook resolv.conf
- In
/usr/lib/dhcpcd/dhcpcd-hooks, we create a hook script (e.g.21-pdnsd.conf) that usespdnsd-ctlto override the nameserver IPs defined in/etc/pdnsd.confwith the ones received by DHCP:# Set the IP of "maindns" entry for pdnsd case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) SRVS="" for X in $new_domain_name_servers; do if [ -z "$SRVS" ]; then SRVS="$X" else SRVS="${SRVS},$X" fi done pdnsd-ctl server 0 up $SRVS ;; PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) # reset to values in /etc/pdnsd.conf pdnsd-ctl config ;; esac
That's it, no big deal ![]()
If you find any problems or disadvantages with this setup, feel free to post them in the comments!
DNS Caching mit pdnsd
Im Zuge des aktuell anlaufenden Nameserver-Hypes (losgetreten durch die ganzen Netzzensur-Debatten) habe ich lokal mal einen DNS-Cache mit pdnsd aufgesetzt - und bin begeistert.
pdnsd behält die gecachten Einträge auch bei einem Neustart des Systems ("p" für "persistent"), weshalb er sich auch für Workstations oder Notebooks eignet.
Sogar mit dem neuen Google-Nameserver (8.8.8.8) als einziger Quelle bemerke ich eine spürbare Beschleunigung beim Browsen, sowie bei AUR-Updates auf meinem Arch.
Empirische Daten folgen, sobald ich Zeit für Benchmarks habe. Vorgegangen bin ich nach dem HowTo im Arch-Wiki.