Saturday, October 9, 2010

DNS configuration on RHEL 5.x (Linux)

Before starting with the steps to configure DNS we need to decide on the IP, Host name for our machine...

Set IP for the machine properly as per your network and add the ip address to the file "/etc/hosts"

Set the hostname properly and make sure you have PEERDNS set to "no" in the file "/etc/sysconfig/network-scripts/ifcfg-eth0"

Now lets begin to configure our machine to a DNS Server
___________________________________________________________________________________

Lets assume the following :
  • Domain is "jagan"
  • Host name is "server1"
  • IP address of our machine is 10.0.0.254
  • Our machine runs on RHEL 5.4
___________________________________________________________________________________

Steps to configure a DNS server on RHEL 5.x
  1. yum -y install bind*
  2. yum -y install caching-nameserver*

    we get output of the above 2 commands as follows if executed as a single command
    -----------------------------------------------------------------------------------------------------
    Loaded plugins: rhnplugin, security
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package bind.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-chroot.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-devel.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-libbind-devel.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-libs.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-sdb.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package bind-utils.i386 30:9.3.6-4.P1.el5 set to be updated
    ---> Package caching-nameserver.i386 30:9.3.6-4.P1.el5 set to be updated
    --> Finished Dependency Resolution
    Dependencies Resolved
    ================================================================================
     Package                  Arch       Version                    Repository
                                                                               Size
    ================================================================================
    Installing:
     bind                     i386       30:9.3.6-4.P1.el5          sri       978 k
     bind-chroot              i386       30:9.3.6-4.P1.el5          sri        44 k
     bind-devel               i386       30:9.3.6-4.P1.el5          sri       2.8 M
     bind-libbind-devel       i386       30:9.3.6-4.P1.el5          sri       440 k
     bind-libs                i386       30:9.3.6-4.P1.el5          sri       857 k
     bind-sdb                 i386       30:9.3.6-4.P1.el5          sri       228 k
     bind-utils               i386       30:9.3.6-4.P1.el5          sri       170 k
     caching-nameserver       i386       30:9.3.6-4.P1.el5          sri        60 k
    Transaction Summary
    ================================================================================
    Install      8 Package(s)        
    Update       0 Package(s)        
    Remove       0 Package(s)        
    Total download size: 5.5 M
    Downloading Packages:
    --------------------------------------------------------------------------------
    Total                                           6.5 MB/s | 5.5 MB     00:00    
    Running rpm_check_debug
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
       Installing     : bind-libs                                                1/8
       Installing     : bind                                                     2/8
       Installing     : bind-utils                                               3/8
       Installing     : caching-nameserver                                       4/8
       Installing     : bind-sdb                                                 5/8
       Installing     : bind-libbind-devel                                       6/8
       Installing     : bind-devel                                               7/8
       Installing     : bind-chroot                                              8/8
    Installed:
      bind.i386 30:9.3.6-4.P1.el5        bind-chroot.i386 30:9.3.6-4.P1.el5       
      bind-devel.i386 30:9.3.6-4.P1.el5  bind-libbind-devel.i386 30:9.3.6-4.P1.el5
      bind-libs.i386 30:9.3.6-4.P1.el5   bind-sdb.i386 30:9.3.6-4.P1.el5          
      bind-utils.i386 30:9.3.6-4.P1.el5  caching-nameserver.i386 30:9.3.6-4.P1.el5
    Complete!
    ----------------------------------------------------------------------------------------------------
  3. Check if the machines ip address is set as desired by you to make DNS work properly on your network
  4. Add ip address in "/etc/hosts"
  5. Make sure you have an entry "PEERDNS = no" in the file "/etc/sysconfig/network-scripts/ifcfg-eth0"
  6. cd /var/named/chroot/var/named
  7. Do a long listing with "ll" in the current folder to find the following 2 files in the listing (as shown in fig-1):
    • localdomain.zone
    • named.local
    (fig -1)  File names in green color
  8. cp localdomain.zone for.jagan.com
  9. cp named.local rev.jagan.com
  10. Set HOSTNAME=
  11. vim /etc/resolv.conf
    edit lines as follows (or) add lines if file is empty
    • nameserver 10.0.0.254
    • search  www.jagan.com
  12. vim /etc/hosts
    enter ip adddress of server at the end of the file
  13. cd /var/named/chroot/etc/
  14. cp named.caching-nameserver.conf named.conf
  15. chown root:named named.conf
  16. vim named.conf
    edit the file
    The text in blue color are the edits done to the original file in the output given below (infact we have added those text)
    ----------------------------------------------------------------------------------------------------
    //
    // 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; 10.0.0.254; };
        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; 10.0.0.0/8; };
        allow-query-cache { localhost; };
    };
    logging {
            channel default_debug {
                    file "data/named.run";
                    severity dynamic;
            };
    };
    view localhost_resolver {
        match-clients        { localhost; 10.0.0.0/8; };
        match-destinations { localhost; 10.0.0.0/8; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
    };
    ----------------------------------------------------------------------------------------------------
  17. vim /etc/named.rfc1912.zones

    edit the file

    ------>  the changes to be made are indicated against the highlighted text in the output below
    -----------------------------------------------------------------------------------------------------
    // 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 "localdomain" IN {
        type master;
        file "localdomain.zone";
        allow-update { none; };
    };

    zone "localhost" IN {   ---> higlighted text to be changed to jagan.com
        type master;
        file "localhost.zone";   ---> to be change to "for.jagan.com"
        allow-update { none; };
    };

    zone "0.0.127.in-addr.arpa" IN {  ---> to be changed to "10"
        type master;
        file "named.local";   ---> to be changed to "rev.jagan.com"
        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; };
    };
    -----------------------------------------------------------------------------------------------------
  18. cd /var/named/chroot/var/named
  19. vim for.jagan.com

    =============== Original file contents ===============
    $TTL    86400
    @        IN SOA    localhost root (
                        42        ; serial (d. adams)
                        3H        ; refresh
                        15M        ; retry
                        1W        ; expiry
                        1D )        ; minimum
                IN NS        localhost
    localhost    IN A        127.0.0.1
    ============================================================

    edit or add lines  as follows

    The edits done are highlighted
    ---------------------------------------------------------------------------------------------------
    $TTL    86400
    @        IN SOA    server1.jagan.com root.server1.jagan.com (
                        42        ; serial (d. adams)
                        3H        ; refresh
                        15M        ; retry
                        1W        ; expiry
                        1D )        ; minimum
                IN NS        server1.jagan.com
    localhost    IN A        127.0.0.1
    server1        IN A        10.0.0.254
    client1        IN A        10.0.0.1
    client2        IN A        10.0.0.2
    client3        IN A        10.0.0.3
    client4        IN A        10.0.0.4
    client5        IN A        10.0.0.5
    client6        IN A        10.0.0.6
    client7        IN A        10.0.0.7
    client8        IN A        10.0.0.8
    client9        IN A        10.0.0.9
    client10    IN A        10.0.0.10

    www1        IN CNAME    client1
    www2        IN CNAME    client2
    www3        IN CNAME    client3
    www4        IN CNAME    client4
    www5        IN CNAME    client5
    www6        IN CNAME    client6
    www7        IN CNAME    client7
    www8        IN CNAME    client8
    www9        IN CNAME    client9
    www10      IN CNAME    client10
  20. vim rev.jagan.com

    =============== Original file contents ===============

    $TTL    86400
    @       IN      SOA     localhost. root.localhost.  (
                                          1997022700 ; Serial
                                          28800      ; Refresh
                                          14400      ; Retry
                                          3600000    ; Expire
                                          86400 )    ; Minimum
            IN      NS      localhost.
    1       IN      PTR     localhost.

    ----------------------------------------------------------------------------------------------------
    edits are as follows
    ----------------------------------------------------------------------------------------------------
    $TTL    86400
    @       IN      SOA     server1.jagan.com. root.server1.jagan.com.  (
                                          1997022700 ; Serial
                                          28800      ; Refresh
                                          14400      ; Retry
                                          3600000    ; Expire
                                          86400 )    ; Minimum
                IN      NS      server1.jagan.com.
    254.0.0     IN      PTR     server1.jagan.com.
    1.0.0       IN      PTR     client1.jagan.com.
    2.0.0       IN      PTR     client2.jagan.com.
    3.0.0       IN      PTR     client3.jagan.com.
    4.0.0       IN      PTR     client4.jagan.com.
    5.0.0       IN      PTR     client5.jagan.com.
    6.0.0       IN      PTR     client6.jagan.com.
    7.0.0       IN      PTR     client7.jagan.com.
    8.0.0       IN      PTR     client8.jagan.com.
    9.0.0       IN      PTR     client9.jagan.com.
    10.0.0      IN      PTR     client10.jagan.com.

    ----------------------------------------------------------------------------------------------------
  21. Now you are almost thru... Just that you need to restart the service called "named" get it up and running...

    service named restart             (or)           /etc/init.d/named restart

    and then

    " chkconfig named on"



    AND if something has gone really wrong then you may come to know when you restart the "named" service.. as it may fail if any error has occured...


    That's it you are done with DNS Server... and its should be up and running fine if there are no typo errors and if everything done as said above..

No comments: