How to make Bind Work in CENTOS 5.x version?

Question: How to Make Bind Work in CENTOS 5.x OS?

Solution:
In CENTOS 5, some of the Bind files are not located on the desired location because of which Bind service does not work properly. On starting Bind you get the following error:[root@localhost ~]# service named start

Locating //etc/named.conf failed:

                                                           [FAILED]

The above error shows that you need to place the "named.conf" file, the Bind configuration file, on the desired location in order to make it work. Locate the required file on your machine:

[root@localhost ~]# locate named.conf

/etc/dbus-1/system.d/named.conf

/usr/share/doc/bind-9.x.x/sample/etc/named.conf

/usr/share/logwatch/default.conf/services/named.conf

/usr/share/man/man5/named.conf.5.gz

You will get a list of paths, similar to the above list. Copy the "named.conf" at /usr/share/doc/bind-9.x.x path to the desired location.

In case the Bind is not chrooted, copy the file in /etc:

[root@localhost ~]# cp /usr/share/doc/bind-9.x.x/sample/etc/named.conf /etc/.

If the Bind id chrooted, copy the "named.conf" file in var/named/chroot/etc:

[root@localhost ~]# cp /usr/share/doc/bind-9.x.x/sample/etc/named.conf /var/named/chroot/etc.

Now, try to start Bind service, if you will get the following error:

[root@localhost ~]# service named start

Starting named:

Error in named configuration:

/etc/named.conf:57: open: /etc/named.root.hints: file not found

                                                           [FAILED] 

Locate the "named.root.hints" file on the system: 

[root@localhost ~]# locate  /etc/named.root.hints

/usr/share/doc/bind-9.x.x/sample/etc/named.root.hints

You will get a list or a single file path, copy the file in /usr/share/doc/bind-9.x.x to /etc, if Bind is not chrooted: 
[root@localhost ~]# cp  /usr/share/doc/bind-9.x.x/sample/etc/named.root.hints /etc/.

 If Bind is chrooted copy the file to:
[root@localhost ~]# cp  /usr/share/doc/bind-9.x.x/sample/etc/named.root.hints /var/named/chroot/etc/. 

Try to start the Bind service now:

[root@localhost ~]# service named restart

Starting named:

Error in named configuration:

/etc/named.conf:63: open: /etc/named.rfc1912.zones: file not found

                                                           [FAILED] 

Now, if you will get the above error, we need to remove some part of data from "named.conf" file. Remove this whole section in the copied "named.conf" file: 

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; };
match-destinations { localhost; };
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 "internal"
{
/* This view will contain zones you want to serve only to "internal" clients
that connect via your directly attached LAN interfaces - "localnets" .
*/
match-clients { localnets; };
match-destinations { localnets; };
recursion yes;
// all views must contain the root hints zone:
include "/etc/named.root.hints";

// include "named.rfc1912.zones";
// you should not serve your rfc1912 names to non-localhost clients.

// These are your "authoritative" internal zones, and would probably
// also be included in the "localhost_resolver" view above :

zone "my.internal.zone" {
type master;
file "my.internal.zone.db";
};
zone "my.slave.internal.zone" {
type slave;
file "slaves/my.slave.internal.zone.db";
masters { /* put master nameserver IPs here */ 127.0.0.1; } ;
// put slave zones in the slaves/ directory so named can update them
};
zone "my.ddns.internal.zone" {
type master;
allow-update { key ddns_key; };
file "slaves/my.ddns.internal.zone.db";
// put dynamically updateable zones in the slaves/ directory so named can update them
};
};
key ddns_key
{
algorithm hmac-md5;
secret "use /usr/sbin/dns-keygen to generate TSIG keys";
};
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 { !localnets; !localhost; };
match-destinations { !localnets; !localhost; };

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

// 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 "my.external.zone" {
type master;
file "my.external.zone.db";
};
};

Now, start Bind service: 

[root@localhost ~]# service named restart

Starting named:                                            [  OK  ]

 Your Bind service will be running now. 

Note: If you want to change chrooted Bind, simply comment the ROOTDIR line in /etc/sysconfig/named file and restart named service.