- Most Recent |
24 hours |
7 days |
30 days |
365 days |
Problem
Konqueror makes a lot of DNS requests, because it lacks a DNS cache. Every time you click on a link on the same page, it asks the name server again and again the same requests. Let’s have a look at the tcpdump output:
hydra linux # tcpdump -i wlan0 port 53 | grep kde
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 96 bytes
03:51:37.814131 IP noname.47046 > fritz.fonwlan.box.domain: 62453+ A? www.kde.org. (29)
03:51:37.815315 IP noname.46355 > fritz.fonwlan.box.domain: 12266+ AAAA? www.kde.org. (29)
03:51:37.818689 IP fritz.fonwlan.box.domain > noname.47046: 62453 1/3/3 A jamaica.kde.org (147)
03:51:37.827959 IP noname.55171 > fritz.fonwlan.box.domain: 34759+ AAAA? www.kde.org. (29)
03:51:38.153790 IP noname.54649 > fritz.fonwlan.box.domain: 59581+ A? www.kde.org. (29)
03:51:38.154227 IP noname.45932 > fritz.fonwlan.box.domain: 1783+ AAAA? www.kde.org. (29)
03:51:38.154527 IP noname.35916 > fritz.fonwlan.box.domain: 63272+ A? www.kde.org. (29)
03:51:38.154703 IP noname.34958 > fritz.fonwlan.box.domain: 40719+ AAAA? www.kde.org. (29)
03:51:38.155532 IP noname.48468 > fritz.fonwlan.box.domain: 29074+ A? www.kde.org. (29)
03:51:38.155786 IP noname.53167 > fritz.fonwlan.box.domain: 6327+ AAAA? www.kde.org. (29)
03:51:38.158576 IP fritz.fonwlan.box.domain > noname.54649: 59581 1/3/3 A jamaica.kde.org (147)
03:51:38.160777 IP fritz.fonwlan.box.domain > noname.35916: 63272 1/3/3 A jamaica.kde.org (147)
03:51:38.165405 IP fritz.fonwlan.box.domain > noname.48468: 29074 1/3/3 A jamaica.kde.org (147)
03:51:43.155083 IP noname.45932 > fritz.fonwlan.box.domain: 1783+ AAAA? www.kde.org. (29)
03:51:43.155317 IP noname.34958 > fritz.fonwlan.box.domain: 40719+ AAAA? www.kde.org. (29)
03:51:43.156320 IP noname.53167 > fritz.fonwlan.box.domain: 6327+ AAAA? www.kde.org. (29)
03:51:48.155660 IP noname.45102 > fritz.fonwlan.box.domain: 22557+ AAAA? www.kde.org. (29)
03:51:48.156134 IP noname.35483 > fritz.fonwlan.box.domain: 7088+ AAAA? www.kde.org. (29)
03:51:48.157225 IP noname.50214 > fritz.fonwlan.box.domain: 3819+ AAAA? www.kde.org. (29)
03:51:53.155423 IP noname.45102 > fritz.fonwlan.box.domain: 22557+ AAAA? www.kde.org. (29)
03:51:53.157183 IP noname.35483 > fritz.fonwlan.box.domain: 7088+ AAAA? www.kde.org. (29)
03:51:53.158334 IP noname.50214 > fritz.fonwlan.box.domain: 3819+ AAAA? www.kde.org. (29)
03:51:58.407589 IP noname.46900 > fritz.fonwlan.box.domain: 27649+ A? www.kde.org. (29)
03:51:58.407952 IP noname.50877 > fritz.fonwlan.box.domain: 40260+ A? www.kde.org. (29)
03:51:58.408142 IP noname.43841 > fritz.fonwlan.box.domain: 65416+ AAAA? www.kde.org. (29)
03:51:58.408324 IP noname.35139 > fritz.fonwlan.box.domain: 626+ AAAA? www.kde.org. (29)
03:51:58.409119 IP noname.40596 > fritz.fonwlan.box.domain: 5619+ A? www.kde.org. (29)
03:51:58.409306 IP noname.56401 > fritz.fonwlan.box.domain: 15192+ AAAA? www.kde.org. (29)
03:51:58.412438 IP fritz.fonwlan.box.domain > noname.46900: 27649 1/3/3 A jamaica.kde.org (147)
03:51:58.413405 IP fritz.fonwlan.box.domain > noname.50877: 40260 1/3/3 A jamaica.kde.org (147)
03:51:58.419296 IP fritz.fonwlan.box.domain > noname.40596: 5619 1/3/3 A jamaica.kde.org (147)
03:52:03.409085 IP noname.43841 > fritz.fonwlan.box.domain: 65416+ AAAA? www.kde.org. (29)
03:52:03.409320 IP noname.35139 > fritz.fonwlan.box.domain: 626+ AAAA? www.kde.org. (29)
As you can see, it asks my router (fritz.fonwlan.box) tons of questions. It would be nice to have a local DNS cache to reduce the number of DNS requests.
pdnsd to the rescue
Installation
pdnsd is a local DNS cache that reduces external DNS requests to a minimum. You can find it in the repository of your distribution. The installation is pretty simple:
# Ubuntu/Debian:
sudo apt-get install pdnsd
# Gentoo:
emerge pdnsd
Configuration
Depending on your distribution, the configuration file is located in different directories. Let’s open it in our editor of choice:
# Ubuntu/Debian:
gksudo gedit /etc/pdnsd.conf
# Gentoo:
nano -w /etc/pdnsd/pdnsd.conf
Here is my pdnsd.conf. It looks complicated, but I think, it is self-explaining:
global {
perm_cache=2048;
cache_dir="/var/cache/pdnsd";
run_as="pdnsd";
server_ip = 127.0.0.1; # Use eth0 here if you want to allow other
# machines on your network to query pdnsd.
status_ctl = on;
query_method=udp_tcp;
min_ttl=15m; # Retain cached entries at least 15 minutes.
max_ttl=1w; # One week.
timeout=10; # Global timeout option (10 seconds).
}
# The following section is most appropriate if you have a fixed connection to
# the Internet and an ISP which provides good DNS servers.
server {
label= "floodnet";
ip = 192.168.178.1; # Put your ISP's DNS-server address(es) here.
timeout=4; # Server timeout; this may be much shorter
# that the global timeout option.
uptest=if; # Test if the network interface is active.
interface=wlan0; # The name of the interface to check.
interval=10m; # Check every 10 minutes.
purge_cache=off; # Keep stale cache entries in case the ISP's
# DNS servers go offline.
}
source {
owner=localhost;
file="/etc/hosts";
}
rr {
name=localhost;
reverse=on;
a=127.0.0.1;
owner=localhost;
soa=localhost,root.localhost,42,86400,900,86400,86400;
}
Basically, you only have to change two lines in the first server section: the interface, which should be the external interface of your computer and the ip, which should point to the IP of your actual name server – for most people, it is the IP of your wireless router.
Starting pdnsd
/etc/init.d/pdnsd start
pdnsd should now listen to port 53:
hydra linux # netstat -ln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 ::ffff:127.0.0.1:53 :::* LISTEN
udp 0 0 ::ffff:127.0.0.1:53 :::*
If all went well, we should now set the nameserver entry of /etc/resolv.conf to our new local DNS cache. It should look like this:
nameserver 127.0.0.1
Testing pdnsd
I’m doing the same request from the beginning of this trick twice. The first time I visit http://www.kde.org/, it fills the local DNS cache, but if I visit it the second time, no DNS requests are made to my router. Here is the tcpdump output:
hydra linux # tcpdump -i wlan0 port 53 | grep kde
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 96 bytes
As you can see, there were no DNS requests made. The second page reload took just a fraction of the time of the first load.
You should now add pdnsd to your standard runlevel.
For more Linux tricks, click here
Don't forget to subscribe to our
RSS/Atom feed to get the latest tricks.








