Saturday, May 7, 2016

Linux : configuring the master DNS server.

master DNS, Domain name system. DNS major role is to convert human readable domain names to machine known numbers (IP Address). World resource connected to the internet or a private network by decentralized naming system.
The Domain Name System delegates the responsibility of assigning domain names and mapping those names to Internet resources by designating authoritative name servers for each domain. Network administrators may delegate authority over sub-domains of their allocated name space to other name servers. This mechanism provides distributed and fault tolerant service and was designed to avoid a single large central database.
Based on working method types of DNS are there, few are mentioned below
  1. Primary / Master DNS
  2. Slave DNS
  3. Forwarding DNS
  4. Caching DNS
  5. Authoritative-Only DNS

Primary / master DNS and Slave DNS Servers

Given the importance of DNS in making services and entire networks accessible, most DNS servers that are authoritative for a zone will have built-in redundancy. There are various terms for the relationships between these servers, but generally, a server can either be a master or a slave in its configuration.
Both master and slave servers are authoritative for the zones they handle. The master does not have any more power over the zones than the slave. The only differentiating factor between a master and a slave server is where they read their zone files from.
A master server reads its zone files from files on the system’s disk. These are usually where the zone administrator adds, edits, or transfers the original zone files.
The slave server receives the zones that it is authoritative for through a zone transfer from one of the master servers for the zone. Once it has these zones, it places them in a cache. If it has to restart, it first checks its cache to see if the zones inside are up-to-date. If not, it requests the updated information from the master server.

Forwarding DNS Server

This approach adds an additional link in the chain of DNS resolution by implementing a forwarding server that simply passes all requests to another DNS server with recursive capabilities (such as a caching DNS server).
The advantage of this system is that it can give you the advantage of a locally accessible cache while not having to do the recursive work (which can result in additional network traffic and can take up substantial resources on high traffic servers). This can also lead to some interesting flexibility in splitting your private and public traffic by forwarding to different servers.

Caching DNS Server

A caching DNS server is a server that handles recursive requests from clients. Almost every DNS server that the operating system’s stub resolver will contact will be a caching DNS server.
Caching servers have the advantage of answering recursive requests from clients. While authoritative-only servers may be ideal for serving specific zone information, caching DNS servers are more broadly useful from a client’s perspective. They make the DNS system of the world accessible to rather dumb client interfaces.

Authoritative-Only DNS Server

An authoritative-only DNS server is a server that only concerns itself with answering the queries for the zones that it is responsible for. Since it does not help resolve queries for outside zones, it is generally very fast and can handle many requests efficiently.

Few DNS Records

A = Address record
PTR  = Pointer record
NS = Name service / server
MX = Mail Exchanger
SOA = State of Authority
CNAME =    Canonical name / Alias Name

master DNS Server Profile

Packages Required   :  bind*
Version    :  9
Daemon  : named
Config File  : /var/named/chroot/etc/named.conf
/var/named/chroot/etc/named.rfc1912.zone
Default zone files location :         /var/named/chroot/var/named/
Port Number  : 53
[root@Techtutorial ~]# yum install bind*
First start named-chroot before named.service because it will generate config files
[root@Techtutorial ~]# systemctl enable named-chroot.service
[root@Techtutorial ~]# systemctl start named-chroot.service
[root@Techtutorial ~]# systemctl enable named.service
[root@Techtutorial ~]# systemctl start named.service
[root@Techtutorial ~]# vim /var/named/chroot/etc/named.conf
options {
        listen-on port 53 { 127.0.0.1; 192.168.2.128; };
        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";
        allow-query     { localhost; 192.168.2.0/24; };
(Default line number is 10-17) As shown above enter your DNS server IP address (which is your server address) and network address which network you want to provide DNS service.
Now edit zones configuration file
[root@Techtutorial ~]# vim /var/named/chroot/etc/named.rfc1912.zones
### Zones Start Here  ####
zone "srinivaslinux.com" IN {
        type master;
        file "srinivaslinux.com";
        allow-update { none; };
};
zone "2.168.192.in-addr.arpa" IN {
        type master;
        file "srinivaslinux.rev.zone";
        allow-update { none; };
};
#### Zoned Ended Here ####
as shown above copy the zone configuration lines (Default line numbers from 19 to 23) and paste there itself. copy the Reverse zone configuration line  (Default line number 31 to 35) and paste there itself. Now modify the copied lines as per your requirement ( which are in pink color).
zone “srinivaslinux.com” IN {  in this line whatever the domain name you would like to configure mention that
file “srinivaslinux.for.zone”;  file name whatever the file name you want you can give
zone “2.168.192.in-addr.arpa” IN { in this line write your IP address in reverse way
file “srinivaslinux.rev.zone”; file name whatever the file name you would like.
Save configuration file and Exit

Creating Zone files

Forward lookup zone – forward lookup zone will convert host name name to IP address
Reverse lookup zone – reverse lookup zone will convert IP address to  host name
change directory path to /var/named/chroot/var/named/
copy the files as per the file names which we have mentioned in above zones configuration file
in this example
named.local –> srinivaslinux.for.zone
named.loopback –> srinivaslinux.rev.zone
[root@Techtutorial named]# cd /var/named/chroot/var/named
[root@Techtutorial named]# cp named.localhost srinivaslinux.for.zone
[root@Techtutorial named]# cp named.loopback srinivaslinux.rev.zone
[root@Techtutorial named]# vim arkit.for.zone 
$TTL 1D
@    IN SOA    TechTutorial.srinivaslinux.com. root.TechTutorial.srinivaslinux.com. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
                NS    TechTutorial.srinivaslinux.com.
arkit.com.             A    192.168.2.128
TechTutorial           A    192.168.2.128
As shown in above configuration TechTutorial.srinivaslinux.com. – DNS Server Name and domain name
add NS record as DNS Server name and domain name (do not forgot to add (dot) yet end)
First A record will be your domain name and DNS server IP address
[root@Techtutorial named]# vim srinivaslinux.rev.zone 
$TTL 1D
@    IN SOA    TechTutorial.srinivaslinux.com. root.TechTutorial.srinivaslinux.com. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    TechTutorial.srinivaslinux.com.
128    PTR    TechTutorial.srinivaslinux.com.
Note: Even do not miss single (dot) which will not start your named service
i have shown single host record as a example if you want to add more records add them
Now change the ownership of created files to named group
[root@Techtutorial named]# chown root:named srinivaslinux.for.zone 
[root@Techtutorial named]# chown root:named srinivaslinux.rev.zone 
Add firewall rule to communicate DNS port out
[root@Techtutorial ~]# firewall-cmd --permanent --add-service=dns
success
[root@Techtutorial ~]# firewall-cmd --reload
success
Now restart your named service.
[root@Techtutorial named]# systemctl restart named.service 
[root@Techtutorial named]# systemctl status named.service 
Now go to client side and add DNS server IP to /etc/resolve.conf
[root@Techtutorial named]# vim /etc/resolve.conf
search srinivaslinux.com
domain srinivaslinux.com
nameserver 192.168.2.128
verify master dns server
# nslookup srinivaslinux.com
#dig srinivaslinux.com
#host 192.168.2.128
#dig -x 192.168.2.128

No comments:

Post a Comment