How To: Configure Caching Nameserver (named)


To configure a caching nameserver on a local machine which will cascade to another previously configured and functional nameserver (may or may not be caching. It’ll generally be your ISP nameserver or the one provided by your organization).


  • Reduces the delay in domain name resolution drastically as the requests for frequently accessed websites are served from cache.


  • named gets a request for domain resolution.
  • It checks whether the request can be satisfied from cache. If the answer is in cache and not stale, the request is satisfied from cache itself saving a lot of time :)
  • If request can’t be satisfied from cache, named queries the first parent. If it replies with the answer, then named will cache the response and subsequent requests for the same domain name will be satisfied from the cache.
  • In case first parent fails to reply, named will query the second parent and so on.

(The working is my understanding of caching-nameserver using wireshark as traffic analysis tool and caching-nameserver may not behave exactly as explained above.)

How to install

named is by default on most of the systems by the package name ‘caching-nameserver‘. If its not present on your system, install using

[root@localhost ~]# yum install caching-nameserver [ENTER]
# If that doesn't work try this
[root@localhost ~]# yum install bind [ENTER]

How to configure

The main configuration file for named resides in /var/named/chroot/etc/named.caching-nameserver.conf which is also soft linked from /etc/named.caching-nameserver.conf . named configuration file supports C/C++ style comments.

For a caching nameserver which will cascade to another nameserver, there is nothing much to be configured. You need to configure “options” block. Below is a configuration file for a machine with IP address cascading to two nameserver and The comments inline explain what each option does.

options {
  // Set the port to 53 which is standard port for DNS.
  // Add the IP address on which named will listen separated by semi-colons.
  // It'll be your own IP address.
  listen-on port 53 {;;};
  // These are default. Leave them as it is.
  directory   "/var/named";
  dump-file   "/var/named/data/cache_dump.db";
  statistics-file "/var/named/data/named_stats.txt";
  memstatistics-file "/var/named/data/named_mem_stats.txt";
  // The machines which are allowed to query this nameserver.
  // Normally you'll allow only your machine. But you can allow other machines also.
  // The address should be separated by semi-colons. To allow a network,
  // the line would be
  // allow-query {localhost;; };
  // Don't forget the semi-colons.
  allow-query     { localhost;; };
  recursion yes;
  // The parent nameservers. List all the nameserver which you can query.
  forwarders {;; };
  forward first;
logging {
        channel default_debug {
                file "data/";
                severity dynamic;
zone "." IN {
  type hint;
  file "";
include "/etc/named.rfc1912.zones";

Start caching-nameserver

Now start the caching-nameserver using the following command

[root@localhost ~]# server named start [ENTER]


[root@localhost ~]# /etc/init.d/named start [ENTER]

To make named start every time your reboot your machine use following command

[root@localhost ~]# chkconfig named on [ENTER]

Using caching-nameserver

To use your caching-nameserver, open /etc/resolv.conf file and add the following line


Comment all other lines in the file, so that finally the file looks like

; generated by /sbin/dhclient-script

Now your system will use your own nameserver (in caching mode) for resolving all domain names. To test if your nameserver use the following command

[root@localhost ~]# dig [ENTER]

Now if you use that command for the second time, the resolution time will be around 2-3 milli seconds while first time it would be around 400-700 milli seconds.


Below is two subsequent runs of dig for . Notice the Query time.

[root@bordeaux SPECS]# dig
; <<>> DiG 9.4.2rc1 <<>>
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7839
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;                  IN      A
;; ANSWER SECTION:           83629   IN      A
;; AUTHORITY SECTION:           79709   IN      NS
;; ADDITIONAL SECTION:        79709   IN      A
;; Query time: 531 msec
;; WHEN: Wed Nov 19 18:04:47 2008
;; MSG SIZE  rcvd: 79
[root@bordeaux SPECS]# dig
; <<>> DiG 9.4.2rc1 <<>>
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64233
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;                  IN      A
;; ANSWER SECTION:           83625   IN      A
;; AUTHORITY SECTION:           79705   IN      NS
;; ADDITIONAL SECTION:        79705   IN      A
;; Query time: 1 msec
;; WHEN: Wed Nov 19 18:04:51 2008
;; MSG SIZE  rcvd: 79
[root@bordeaux SPECS]#

4 thoughts on “How To: Configure Caching Nameserver (named)

  1. Fantastic. Wish I’d found this page a week ago.
    That’s some damn useful blogging Kulbir San, nice work.

  2. I’m wondering how can I install the new version of bind on my FC7 machine. I downloaded the src from isc, but it has been a pain to update my version of bind to the more recent.

  3. I am trying to set up a dns caching server on windows 7 X64 for 10 computers in my shop running windows xp sp3. First of all is this going to work if I do this because it seems like it might be working but I am confused about something in your config.

    zone “.” IN {
    type hint;
    file “”;
    include “/etc/named.rfc1912.zones”;

    You have these zones but I though there are no zones in a dns caching only server. I dont get what the incude is for do I even need that? Also in BIND 9 I dont see a resolve.conf file.

Comments are closed.