Addition/Setup.Bind.As.Cache.DNS.Server

From iRedMail

(Difference between revisions)
Jump to: navigation, search
(Merge)
 
(12 intermediate revisions not shown)
Line 1: Line 1:
 +
<table border="1">
 +
<tr>
 +
<th>Author</th>
 +
<td>[http://www.iredmail.org/forum/user528.html hoho]</td>
 +
</tr>
 +
</table>
 +
=Mission=
=Mission=
-
 
Configure a caching nameserver on a iRedMail server to speed up DNS lookup.
Configure a caching nameserver on a iRedMail server to speed up DNS lookup.
-
 
= Advantage =
= Advantage =
Line 24: Line 29:
We choose '''BIND''' which is the most common package on DNS server.
We choose '''BIND''' which is the most common package on DNS server.
-
To check the package present or not on the system, just using
+
* On RHEL/CentOS:
-
 
+
-
        rpm -qa |grep bind
+
-
        rpm -qa |grep caching-nameserver
+
-
 
+
-
 
+
-
by default on iRedMail server, the result is:
+
-
 
+
-
''[root@mail ~]# rpm -qa |grep bind''
+
-
 
+
-
ypbind-1.19-12.el5
+
-
 
+
-
bind-libs-9.3.6-4.P1.el5_4.2
+
-
 
+
-
bind-utils-9.3.6-4.P1.el5_4.2
+
-
 
+
-
 
+
-
the package we need on cache named server is
+
-
 
+
-
* bind
+
-
* bind-chroot
+
-
* bind-util
+
-
* caching-nameserver
+
-
 
+
-
If they are not present on your system, install using
+
-
 
+
{{cmd|<pre># yum install caching-nameserver bind-chroot</pre>}}
{{cmd|<pre># yum install caching-nameserver bind-chroot</pre>}}
-
all the components we need will be installed
+
* On Debian/Ubuntu:
 +
* On FreeBSD:
= Configure Bind =
= Configure Bind =
-
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.
+
The main configuration file for named is /etc/named.caching-nameserver.conf (actually, it's a symbol link to /var/named/chroot/etc/named.caching-nameserver.conf).
Below is a configuration file for a machine for iRedMail localhost only. The comments inline explain what each option does.  
Below is a configuration file for a machine for iRedMail localhost only. The comments inline explain what each option does.  
-
Since the DNS cache server is for iRedMail local use only, so the IP listen and query is only for localhost. If you want to share the DNS caching for local network for any query, you need to modify the config file to your own.
+
{{cfg|/etc/named.caching-nameserver.conf|<pre>
 +
options {
 +
        // <-- BELOW ARE DEFAULT SETTINGS SHIPPED IN RHEL/CENTOS -->
 +
        listen-on port 53 { 127.0.0.1; };
 +
        listen-on-v6 port 53 { ::1; };
 +
        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 '''BOLD''' characters indicate that you need to enter by yourself.
 
-
{{cfg||<pre>
 
-
        //
 
-
        // named.caching-nameserver.conf
 
-
        //
 
-
        // Provided by Red Hat caching-nameserver package to configure the
 
-
        // ISC BIND named(8) DNS server as a caching only nameserver
 
-
        // (as a localhost DNS resolver only).
 
-
        //
 
-
        // See /usr/share/doc/bind*/sample/ for example named configuration files.
 
-
        //
 
-
        // DO NOT EDIT THIS FILE - use system-config-bind or an editor
 
-
        // to create named.conf - edits to this file will be lost on
 
-
        // caching-nameserver package upgrade.
 
-
        //
 
-
                options {
 
-
                listen-on port 53 { 127.0.0.1; };
 
-
                listen-on-v6 port 53 { ::1; };
 
-
                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";
 
-
                '''forward first;  //using external DNS if no reference on this server'''
 
-
                '''forwarders {'''
 
-
                        '''202.76.4.18;    // CPCNet DNS you should use the DNS from your ISP'''
 
-
                        '''8.8.8.8;        // Google DNS here is the sample DNS'''
 
-
                '''};'''
 
         // Those options should be used carefully because they disable port
         // Those options should be used carefully because they disable port
         // randomization
         // randomization
         // query-source    port 53;
         // query-source    port 53;
         // query-source-v6 port 53;
         // query-source-v6 port 53;
-
       
+
 
-
                allow-query    { localhost; };
+
        allow-query    { localhost; };
-
                allow-query-cache { localhost; };
+
        allow-query-cache { localhost; };
-
         };
+
         // <-- END DEFAULT SETTINGS -->
-
        logging {
+
 
-
                channel default_debug {
+
// <-- Add or modify below lines -->
-
                        file "data/named.run";
+
         forward first; //using external DNS if no reference on this server
-
                        severity dynamic;
+
         forwarders {
-
                };
+
            202.76.4.18;   // CPCNet DNS you should use the DNS from your ISP
-
         };
+
            8.8.8.8;       // Google DNS here is the sample DNS
-
         view localhost_resolver {
+
-
                match-clients      { localhost; };
+
-
                match-destinations { localhost; };
+
-
                recursion yes;
+
-
                include "/etc/named.rfc1912.zones";
+
         };
         };
 +
// <-- END -->
 +
};
</pre>}}
</pre>}}
-
To use your caching-nameserver, open ''/etc/resolv.conf'' file and add the following line to make all query carry on the local iRedMail only.
 
-
'''nameserver 127.0.0.1'''
+
Since the DNS cache server is for iRedMail local use only, so the IP listen and query is only for localhost. If you want to share the DNS caching for local network for any query, you need to modify the config file to your own.
-
Comment all other lines in the file, so that finally the file looks like
+
Start named now, and make it start while system startup:
 +
* On RHEL/CentOS:
 +
{{cmd|<pre>
 +
# /etc/init.d/named restart
 +
# chkconfig --level 345 named on
 +
</pre>}}
-
  # search yourdomain.com
+
* On Debian/Ubuntu:
-
  # nameserver 202.76.4.18
+
* On FreeBSD:
-
  # nameserver 8.8.8.8
+
-
  nameserver 127.0.0.1
+
-
save and restart the service:
+
= Use Bind as DNS server on your server =
 +
To use named, just open ''/etc/resolv.conf'' file and add the following line, it will make all DNS query carried on local named only.
-
  [root@mail ~]# service network restart
+
{{cfg|/etc/resolv.conf|<pre>nameserver 127.0.0.1</pre>}}
 +
 
 +
If local named doesn't have DNS records which you requested, it will forward requests to DNS servers which listed in '''forwarders {}''' in named config file.
Now try to ping any domain and you will find that the server cannot resolve any domain name. That mean the domain only query itself the server itself.
Now try to ping any domain and you will find that the server cannot resolve any domain name. That mean the domain only query itself the server itself.
To start the DNS caching service
To start the DNS caching service
-
 
+
{{cmd|<pre># service named start</pre>}}
-
  [root@mail ~]# service named start
+
and then check the log to see the service starting status log
and then check the log to see the service starting status log
-
[root@mail ~]# cat /var/log/messages
+
{{cmd|<pre># cat /var/log/messages
  Mar 10 12:20:03 mail named[1522]: starting BIND 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 -u named -c /etc/named.caching-nameserver.conf -t /var/named/chroot
  Mar 10 12:20:03 mail named[1522]: starting BIND 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 -u named -c /etc/named.caching-nameserver.conf -t /var/named/chroot
Line 154: Line 117:
  Mar 10 12:20:03 mail named[1522]: zone localdomain/IN/localhost_resolver: loaded serial 42
  Mar 10 12:20:03 mail named[1522]: zone localdomain/IN/localhost_resolver: loaded serial 42
  Mar 10 12:20:03 mail named[1522]: zone localhost/IN/localhost_resolver: loaded serial 42
  Mar 10 12:20:03 mail named[1522]: zone localhost/IN/localhost_resolver: loaded serial 42
 +
</pre>}}
This mean the service is started successfully.
This mean the service is started successfully.
Line 161: Line 125:
To make the DNS caching service start automatically everytime system bootup, simply enter:
To make the DNS caching service start automatically everytime system bootup, simply enter:
-
  [root@mail ~]#  chkconfig named on
+
{{cmd|<pre>#  chkconfig --level 345 named on</pre>}}
Using caching-nameserver
Using caching-nameserver
Line 167: Line 131:
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
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 fedora.co.in  
+
{{cmd|<pre># dig fedora.co.in</pre>}}
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.
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.
Line 174: Line 138:
Below is two subsequent runs of dig for fedora.co.in . Notice the Query time.
Below is two subsequent runs of dig for fedora.co.in . Notice the Query time.
-
  [root@bordeaux SPECS]# dig fedora.co.in
+
{{cmd|<pre># dig fedora.co.in
   ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> fedora.co.in
   ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> fedora.co.in
Line 209: Line 173:
   ;; WHEN: Wed Mar 10 15:18:56 2010
   ;; WHEN: Wed Mar 10 15:18:56 2010
   ;; MSG SIZE  rcvd: 277
   ;; MSG SIZE  rcvd: 277
-
 
+
</pre>}}
The query time is long at the first time.
The query time is long at the first time.
Enter the command again and then you will see the query time is greatly reduced that mean the caching service running successfully.
Enter the command again and then you will see the query time is greatly reduced that mean the caching service running successfully.

Current revision as of 16:58, 29 March 2010

Author hoho

Contents

Mission

Configure a caching nameserver on a iRedMail server to speed up DNS lookup.

Advantage

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


Working

"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.


Install Bind

We choose BIND which is the most common package on DNS server.

  • On RHEL/CentOS:
Terminal:
# yum install caching-nameserver bind-chroot
  • On Debian/Ubuntu:
  • On FreeBSD:

Configure Bind

The main configuration file for named is /etc/named.caching-nameserver.conf (actually, it's a symbol link to /var/named/chroot/etc/named.caching-nameserver.conf).

Below is a configuration file for a machine for iRedMail localhost only. The comments inline explain what each option does.

File: /etc/named.caching-nameserver.conf
options {
        // <-- BELOW ARE DEFAULT SETTINGS SHIPPED IN RHEL/CENTOS -->
        listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };
        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";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;

        allow-query     { localhost; };
        allow-query-cache { localhost; };
        // <-- END DEFAULT SETTINGS -->

// <-- Add or modify below lines -->
        forward first;  //using external DNS if no reference on this server
        forwarders {
            202.76.4.18;    // CPCNet DNS you should use the DNS from your ISP
            8.8.8.8;        // Google DNS here is the sample DNS
        };
// <-- END -->
};

Since the DNS cache server is for iRedMail local use only, so the IP listen and query is only for localhost. If you want to share the DNS caching for local network for any query, you need to modify the config file to your own.

Start named now, and make it start while system startup:

  • On RHEL/CentOS:
Terminal:
# /etc/init.d/named restart
# chkconfig --level 345 named on
  • On Debian/Ubuntu:
  • On FreeBSD:

Use Bind as DNS server on your server

To use named, just open /etc/resolv.conf file and add the following line, it will make all DNS query carried on local named only.

File: /etc/resolv.conf
nameserver 127.0.0.1

If local named doesn't have DNS records which you requested, it will forward requests to DNS servers which listed in forwarders {} in named config file.

Now try to ping any domain and you will find that the server cannot resolve any domain name. That mean the domain only query itself the server itself.

To start the DNS caching service

Terminal:
# service named start

and then check the log to see the service starting status log

Terminal:
# cat /var/log/messages

 Mar 10 12:20:03 mail named[1522]: starting BIND 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 -u named -c /etc/named.caching-nameserver.conf -t /var/named/chroot
 Mar 10 12:20:03 mail named[1522]: adjusted limit on open files from 1024 to 1048576
 Mar 10 12:20:03 mail named[1522]: found 1 CPU, using 1 worker thread
 Mar 10 12:20:03 mail named[1522]: using up to 4096 sockets
 Mar 10 12:20:03 mail named[1522]: loading configuration from '/etc/named.caching-nameserver.conf'
 Mar 10 12:20:03 mail named[1522]: using default UDP/IPv4 port range: [1024, 65535]
 Mar 10 12:20:03 mail named[1522]: using default UDP/IPv6 port range: [1024, 65535]
 Mar 10 12:20:03 mail named[1522]: listening on IPv6 interface lo, ::1#53
 Mar 10 12:20:03 mail named[1522]: listening on IPv4 interface lo, 127.0.0.1#53
 Mar 10 12:20:03 mail named[1522]: command channel listening on 127.0.0.1#953
 Mar 10 12:20:03 mail named[1522]: command channel listening on ::1#953
 Mar 10 12:20:03 mail named[1522]: the working directory is not writable
 Mar 10 12:20:03 mail named[1522]: zone 0.in-addr.arpa/IN/localhost_resolver: loaded serial 42
 Mar 10 12:20:03 mail named[1522]: zone 0.0.127.in-addr.arpa/IN/localhost_resolver: loaded serial 1997022700
 Mar 10 12:20:03 mail named[1522]: zone 255.in-addr.arpa/IN/localhost_resolver: loaded serial 42
 Mar 10 12:20:03 mail named[1522]: zone 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN/localhost_resolver: loaded serial  1997022700
 Mar 10 12:20:03 mail named[1522]: zone localdomain/IN/localhost_resolver: loaded serial 42
 Mar 10 12:20:03 mail named[1522]: zone localhost/IN/localhost_resolver: loaded serial 42

This mean the service is started successfully.

Now you can try to ping any domain without any problem.

To make the DNS caching service start automatically everytime system bootup, simply enter:

Terminal:
#  chkconfig --level 345 named on

Using caching-nameserver

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

Terminal:
# dig fedora.co.in

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.

Example Below is two subsequent runs of dig for fedora.co.in . Notice the Query time.

Terminal:
# dig fedora.co.in

  ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> fedora.co.in
  ;; global options:  printcmd
  ;; Got answer:
  ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43694
  ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 9
  
  ;; QUESTION SECTION:
  ;fedora.co.in.                  IN      A
  
  ;; ANSWER SECTION:
  fedora.co.in.           18199   IN      A       174.136.1.134
  
  ;; AUTHORITY SECTION:
  fedora.co.in.           31974   IN      NS      ns4.webcomindia.com.
  fedora.co.in.           31974   IN      NS      ns1.webcomindia.com.
  fedora.co.in.           31974   IN      NS      ns2.webcomindia.com.
  fedora.co.in.           31974   IN      NS      ns3.webcomindia.com.
  
  ;; ADDITIONAL SECTION:
  ns1.webcomindia.com.    31976   IN      A       67.15.47.189
  ns1.webcomindia.com.    31976   IN      A       67.15.253.220
  ns1.webcomindia.com.    31976   IN      A       67.15.253.251
  ns3.webcomindia.com.    31976   IN      A       67.15.253.252
  ns3.webcomindia.com.    31976   IN      A       67.15.47.188
  ns3.webcomindia.com.    31976   IN      A       67.15.253.219
  ns4.webcomindia.com.    166378  IN      A       66.249.5.122
  ns4.webcomindia.com.    166378  IN      A       66.249.5.25
  ns4.webcomindia.com.    166378  IN      A       66.249.5.105
  
  ''';; Query time: 531 msec'''
  ;; SERVER: 127.0.0.1#53(127.0.0.1)
  ;; WHEN: Wed Mar 10 15:18:56 2010
  ;; MSG SIZE  rcvd: 277

The query time is long at the first time.

Enter the command again and then you will see the query time is greatly reduced that mean the caching service running successfully.

Personal tools