Posts Tagged ‘How to configure linux dns server’

Linux:How to configure/secure public primary/secondary bind dns server

Wednesday, September 1st, 2010

Localhost Resolver :
(a) install bind

yum install bind bind-chroot bind-devel

(b) Copy named.conf and related files from /usr/share/doc/bind-9.3.6/sample/etc/

cp /usr/share/doc/bind-9.3.6/sample/etc/* /var/named/chroot/etc/

(c) File lists in /var/named/chroot/etc are as bellows :

[root@publicdns1 etc]# ls
localtime   named.rfc1912.zones  rndc.conf
named.conf  named.root.hints     rndc.key

Check the Ownership of files. Ownership should be root:named as
bellow:

[root@publicdns1 etc]# pwd
/var/named/chroot/etc
[root@publicdns1 etc]# ls -al
total 64
drwxr-x--- 2 root named 4096 Aug 28 13:38 .
drwxr-x--- 6 root named 4096 Aug 28 13:37 ..
-rw-r--r-- 1 root root  3661 Aug 24 12:53 localtime
-rw-r--r-- 1 root named 5299 Aug 28 13:38 named.conf
-rw-r--r-- 1 root named  775 Aug 28 12:20 named.rfc1912.zones
-rw-r--r-- 1 root named  524 Aug 28 12:20 named.root.hints
-rw-r--r-- 1 root named    0 Aug 28 12:20 rndc.conf
-rw-r----- 1 root named  113 Aug 28 12:12 rndc.key
[root@publicdns1 etc]#

If the ownership is not right then we can change it as follows :

chown root:named named.conf  named.rfc1912.zones named.root.hints rndc.conf  rndc.key

(d) Copy named.root into /var/named/chroot/var/named directory

cp /usr/share/doc/bind-9.3.6/sample/var/named/named.root  /var/named/chroot/var/named/

File lists are :

[root@publicdns1 named]# ls
data  domain.co.uk.zone  named.root  slaves
[root@publicdns1 named]#

(e) For allowing internal pc’s to resolve dns request and for internal host name , we need to work on “view “localhost_resolver” ” section as bellow

view "localhost_resolver"
{
/* This view sets up named to be a localhost resolver ( caching only nameserver                                              ).
 * If all you want is a caching-only nameserver, then you need only define this                                              view:
 */
        match-clients           { localhost;10.0.0.0/24; };
        match-destinations      { localhost;10.0.0.0/24; };
        recursion yes;
        # all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        /* these are zones that contain definitions for all the localhost
         * names and addresses, as recommended in RFC1912 - these names should
         * ONLY be served to localhost clients:
         */
        include "/etc/named.rfc1912.zones";
};

Note : all the internal zone information will be placed on named.rfc1912.zones files

(f) Now edit named.rfc1912.zones which is located /var/named/chroot/etc
and enter bellow lines

zone “internaldomain.local” IN {

type master;
file “internaldomain.local.zone”;
};

So the Edited named.rfc1912.zones file be like bellow

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
//zone "." IN {
//      type hint;
//      file "named.ca";
//};
zone "internaldomain.local" IN {
 
        type master;
        file "internaldomain.local.zone";
 
};
 
zone "localdomain" IN {
        type master;
        file "localdomain.zone";
        allow-update { none; };
};
 
zone "localhost" IN {
        type master;
        file "localhost.zone";
        allow-update { none; };
};
 
zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "named.local";
        allow-update { none; };
};
 
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 {
        type master;
        file "named.ip6.local";
        allow-update { none; };
};
 
zone "255.in-addr.arpa" IN {
        type master;
        file "named.broadcast";
        allow-update { none; };
};
 
zone "0.in-addr.arpa" IN {
        type master;
        file "named.zero";
        allow-update { none; };
};

(g)

create a zone file internaldomain.local.zone file in /var/named/chroot/var/named like bellow:

$TTL    86400
@               IN SOA  @       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
 
                          IN NS           internaldns
                          IN MX   10     internalmailserver
                          IN        A      10.0.0.20
internaldns            IN        A      10.0.0.9
Account               IN        A       10.0.0.6
internalmailserver   IN        A   10.0.0.10
www                    IN        A       10.0.0.20

Note : make sure you have permission as bellow or bind would not be able to read it.

chown root:named internaldomain.local.zone

Primary Server:

(A)
Create zone entries in named.conf
Since This server will work as public dns server,We will create zone entries for example.co.uk under external views.

view    "external"
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subnets:
 */
        match-clients           { any; };
        match-destinations      { any; };
 
        recursion no;
        // you'd probably want to deny recursion to external clients, so you don't
        // end up providing free DNS service to all takers
 
    allow-query-cache { none; };
        // Disable lookups for any cached data and root hints
 
        // all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:
 
        ### Add Authoritiative zone for example.co.uk#######
        zone "example.co.uk" IN {
        type master;
        file "example.co.uk.zone";
        allow-update { none; };
        allow-transfer { 22.33.44.55; };//only this host will received updates from this master server.
 
};
 
};

Secondary Server :

Follow every steps from beginning . We just need to make changes on named.conf file to allow slave to download zone file, updates from master server.

view    "external"
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subnets:
 */
        match-clients           { any; };
        match-destinations      { any; };
 
        recursion no;
        // you'd probably want to deny recursion to external clients, so you don't
        // end up providing free DNS service to all takers
 
    allow-query-cache { none; };
        // Disable lookups for any cached data and root hints
 
        // all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:
 
        ### Add Authoritiative zone for example.co.uk#######
      zone "example.co.uk" IN {
        type slave;
        file "slaves/example.co.uk.zone";
        masters { 55.55.55.55 ;};
};
 
};

Full named.conf file for Primary Name server(Public + Local host resolver :

 cat named.conf
//
// Sample named.conf BIND DNS server 'named' configuration file
// for the Red Hat BIND distribution.
//
// See the BIND Administrator's Reference Manual (ARM) for details, in:
//   file:///usr/share/doc/bind-*/arm/Bv9ARM.html
// Also see the BIND Configuration GUI : /usr/bin/system-config-bind and
// its manual.
//
options
{
        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;
 
        // Put files that named is allowed to write in the data/ directory:
        directory "/var/named"; // the default
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
 
};
logging
{
/*      If you want to enable debugging, eg. using the 'rndc trace' command,
 *      named will try to write the 'named.run' file in the $directory (/var/nam                                             ed).
 *      By default, SELinux policy does not allow named to modify the /var/named                                              directory,
 *      so put the default debug log file in data/ :
 */
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
//
// All BIND 9 zones are in a "view", which allow different zones to be served
// to different types of client addresses, and for options to be set for groups
// of zones.
//
// By default, if named.conf contains no "view" clauses, all zones are in the
// "default" view, which matches all clients.
//
// If named.conf contains any "view" clause, then all zones MUST be in a view;
// so it is recommended to start off using views to avoid having to restructure
// your configuration files in the future.
//
view "localhost_resolver"
{
/* This view sets up named to be a localhost resolver ( caching only nameserver                                              ).
 * If all you want is a caching-only nameserver, then you need only define this                                              view:
 */
        match-clients           { localhost;10.0.0.0/24; };
        match-destinations      { localhost;10.0.0.0/24; };
        recursion yes;
        # all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        /* these are zones that contain definitions for all the localhost
         * names and addresses, as recommended in RFC1912 - these names should
         * ONLY be served to localhost clients:
         */
        include "/etc/named.rfc1912.zones";
};
view    "external"
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subn                                             ets:
 */
        match-clients           { any; };
        match-destinations      { any; };
 
        recursion no;
        // you'd probably want to deny recursion to external clients, so you don                                             't
        // end up providing free DNS service to all takers
 
        allow-query-cache { none; };
        // Disable lookups for any cached data and root hints
 
        // all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:
 
            zone "example.co.uk" IN {
        type master;
        file "example.co.uk.zone";
        allow-update { none; };
        allow-transfer { 22.33.44.55; };//only this host will received updates from this master server.
 
};
 
};

Full named.conf for Public Slave server

 cat named.conf
//
// Sample named.conf BIND DNS server 'named' configuration file
// for the Red Hat BIND distribution.
//
// See the BIND Administrator's Reference Manual (ARM) for details, in:
//   file:///usr/share/doc/bind-*/arm/Bv9ARM.html
// Also see the BIND Configuration GUI : /usr/bin/system-config-bind and
// its manual.
//
options
{
        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;
 
        // Put files that named is allowed to write in the data/ directory:
        directory "/var/named"; // the default
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
 
};
logging
{
/*      If you want to enable debugging, eg. using the 'rndc trace' command,
 *      named will try to write the 'named.run' file in the $directory (/var/nam                                             ed).
 *      By default, SELinux policy does not allow named to modify the /var/named                                              directory,
 *      so put the default debug log file in data/ :
 */
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
//
// All BIND 9 zones are in a "view", which allow different zones to be served
// to different types of client addresses, and for options to be set for groups
// of zones.
//
// By default, if named.conf contains no "view" clauses, all zones are in the
// "default" view, which matches all clients.
//
// If named.conf contains any "view" clause, then all zones MUST be in a view;
// so it is recommended to start off using views to avoid having to restructure
// your configuration files in the future.
//
view "localhost_resolver"
{
/* This view sets up named to be a localhost resolver ( caching only nameserver                                              ).
 * If all you want is a caching-only nameserver, then you need only define this                                              view:
 */
        match-clients           { localhost;10.0.0.0/24; };
        match-destinations      { localhost;10.0.0.0/24; };
        recursion yes;
        # all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        /* these are zones that contain definitions for all the localhost
         * names and addresses, as recommended in RFC1912 - these names should
         * ONLY be served to localhost clients:
         */
        include "/etc/named.rfc1912.zones";
};
view    "external"
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subn                                             ets:
 */
        match-clients           { any; };
        match-destinations      { any; };
 
        recursion no;
        // you'd probably want to deny recursion to external clients, so you don                                             't
        // end up providing free DNS service to all takers
 
        allow-query-cache { none; };
        // Disable lookups for any cached data and root hints
 
        // all views must contain the root hints zone:
        include "/etc/named.root.hints";
 
        // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:
 
        zone "example.co.uk" IN {
        type slave;
        file "slaves/example.co.uk.zone";
        masters { 55.55.55.55 ;};
};
 
};

Securing Name server :
(a) Dont End up providing free dns service for every one

options {
     recursion no;
};

(b)

options {
      fetch-glue no;
};

(c)Allow zone transfer from specific host

 ### Add Authoritiative zone for example.co.uk#######
        zone "example.co.uk" IN {
        type master;
        file "example.co.uk.zone";
        allow-update { none; };
        allow-transfer { 22.33.44.55; };//only this host will received updates from this master server.

(d) Don’t disclose Bind version

options {
     version "Not disclosed";
 
};