{"id":688,"date":"2012-09-17T22:32:23","date_gmt":"2012-09-17T20:32:23","guid":{"rendered":"http:\/\/www.shukko.com\/x3\/?p=688"},"modified":"2012-09-17T22:32:23","modified_gmt":"2012-09-17T20:32:23","slug":"speedup-dns-requests-with-a-local-cache-debian","status":"publish","type":"post","link":"https:\/\/www.shukko.com\/x3\/2012\/09\/17\/speedup-dns-requests-with-a-local-cache-debian\/","title":{"rendered":"Speedup DNS requests with a local cache Debian"},"content":{"rendered":"<p>orjinal link: http:\/\/www.debian-administration.org\/articles\/390<\/p>\n<p>One common server bottleneck is DNS lookups. Many common server tasks such as from looking up hostnames to write Apache logfiles and processing incoming mail require the use of DNS queries. If you&#8217;re running a high-traffic system it might be useful to cache previous lookups.<\/p>\n<p>There are several different packages you can use for caching DNS requests &#8211; including <tt>bind<\/tt>, <tt>djbdns<\/tt>, <tt>dnsmasq<\/tt> and <tt>pdnsd<\/tt>.<\/p>\n<p>The <a href=\"http:\/\/packages.debian.org\/pdnsd\">pdnsd package<\/a> is a very simple and lightweight tool for DNS caching. It will, like many of the other systems, act as a small DNS server forwarding requests to a &#8220;real&#8221; DNS server and caching the responses.<\/p>\n<p>When <tt>pdnsd<\/tt> is stopped it will save all the lookups which have been made against it so they may be reloaded when it starts again.<\/p>\n<p>Installation is very straightforward:<\/p>\n<pre>apt-get install pdnsd<\/pre>\n<p>Once installed the software is configured via the file <tt>\/etc\/pdnsd.conf<\/tt>.<\/p>\n<p>To configure the software you must do two things:<\/p>\n<ul>\n<li>Configure <tt>pdnsd<\/tt> so that it will forward requests it doesn&#8217;t know about to a real DNS server, letting it cache those results.<\/li>\n<li>Update your system so that DNS lookups against the newly installed cache, or proxy.<\/li>\n<\/ul>\n<p>Once you&#8217;ve completed these two steps all DNS lookups upon your system will be cached, and your DNS lookups should be much faster.<\/p>\n<p>Upon your Debian GNU\/Linux system you configure the DNS server(s) which are being used by means of the file, <tt>\/etc\/resolv.conf<\/tt>, this file will contain a list of name servers to query, perhaps along with a search domain to be used for unqualified hosts.<\/p>\n<p>To tell your server to make DNS queries against the freshly installed server you would update that file to read:<\/p>\n<pre>nameserver 127.0.0.1<\/pre>\n<p>The next thing to do is to edit the <tt>pdnsd<\/tt> configuration file <tt>\/etc\/pdnsd.conf<\/tt> to specify which DNS servers the cache should use for its own lookups &#8211; these will most likely be your ISPs nameservers.<\/p>\n<p>Locate the section of the configuration file which starts with <tt>server<\/tt> and add the IP address:<\/p>\n<pre>#\r\n#  Specify the IP address of the real DNS server to query against here:\r\n#\r\nserver {\r\n        ip=11.22.33.44;   \r\n        timeout=30;\r\n        interval=30;\r\n        uptest=ping;\r\n        ping_timeout=50;\r\n        purge_cache=off;\r\n}<\/pre>\n<p>With this setting updated you can restart the caching service:<\/p>\n<pre>root@itchy:\/etc# \/etc\/init.d\/pdnsd restart\r\nRestarting proxy DNS server: pdnsd.\r\nroot@itchy:\/etc#<\/pre>\n<p>If you wish to add more DNS servers to query against you can add them seperated by commas, or you can add multiple <tt>ip=<\/tt> lines such as these two examples:<\/p>\n<pre>       # Several IPs seperated by commas.\r\n       ip=11.22.33.44,111.222.333.444;\r\n\r\n       # Easier to read - one per line:\r\n       ip=11.22.33.44;\r\n       ip=111.222.333.444;<\/pre>\n<p>For more details of the supported options please consult the documentation by running &#8220;<tt>man pdnsd.conf<\/tt>&#8220;.<\/p>\n<p>You can test the cache is working by issuing a manual request to it:<\/p>\n<pre>root@itchy:\/etc# dig  @localhost example.com mx\r\n\r\n;; QUESTION SECTION:\r\n;example.com.                   IN      MX\r\n\r\n;; AUTHORITY SECTION:\r\nexample.com.            86400   IN      SOA     dns1.icann.org. hostmaster.icann.org.\r\n\r\n;; Query time: 2224 msec\r\n;; SERVER: 192.168.1.50#53(192.168.1.50)\r\n;; WHEN: Sun Apr 23 21:47:41 2006\r\n;; MSG SIZE  rcvd: 90<\/pre>\n<p>Here we used the <tt>dig<\/tt> command (part of the <a href=\"http:\/\/packages.debian.org\/dnsutils\">dnsutils package<\/a>) to lookup the MX record of the domain name <tt>example.com<\/tt>. Notice at the bottom it shows &#8220;Query time: 2224msec&#8221;? Lets run that same query again &#8211; if our cache is working correctly it should be significantly faster:<\/p>\n<pre>root@itchy:\/etc# dig  @itchy example.com mx |grep time\r\n;; Query time: 1 msec<\/pre>\n<p>Much faster \ud83d\ude42<\/p>\n<p>(Yes DNS queries are ordinarily cached to a certain extent; so you&#8217;d expect the speedup even without our explicit DNS caching server&#8230;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>orjinal link: http:\/\/www.debian-administration.org\/articles\/390 One common server bottleneck is DNS lookups. Many common server tasks such as from looking up hostnames to write Apache logfiles and processing incoming mail require the use of DNS queries. If you&#8217;re running a high-traffic system it might be useful to cache previous lookups. There are several different packages you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-688","post","type-post","status-publish","format-standard","hentry","category-kategerisiz"],"_links":{"self":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":1,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/688\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/posts\/688\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/media?parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/categories?post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shukko.com\/x3\/wp-json\/wp\/v2\/tags?post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}