Skip to main content

Setup DNS-Server on centOS-7 (Master-Slave mode)

Setup Primary (Master) DNS Server

Install bind9 packages on your server. Run the following command:
"yum install bind bind-utils -y"

1. Configure DNS Server

Edit ‘/etc/named.conf’ file.
vi /etc/named.conf
Add the lines as shown in bold:
//
// named.conf
//
// Provided by Red Hat bind 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.
//

options {
    listen-on port 53 { 127.0.0.1; [Master-dns ip];}; ### Master DNS IP ###
#    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.1.0/24;}; ### IP Range ###
    allow-transfer{ localhost; [slave-dns ip]; };   ### Slave DNS IP ###

    /* 
     - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
     - If you are building a RECURSIVE (caching) DNS server, you need to enable 
       recursion. 
     - If your recursive DNS server has a public IP address, you MUST enable access 
       control to limit queries to your legitimate users. Failing to do so will
       cause your server to become part of large scale DNS amplification 
       attacks. Implementing BCP38 within your network would greatly
       reduce such attack surface 
    */
    recursion yes;

    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
    type hint;
    file "named.ca";
};

zone "learnwithak.local" IN { 
type master; 
file "forward.learnwithak"; 
allow-update { none; }; 
}; 
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

2 Create Forward Zone

Create forward.learnwithak file in the ‘/var/named’ directory.
vi /var/named/forward.learnwithak
Add the following lines:
$TTL 86400
@ IN SOA ehs-dns-master.learnwithak.local. root.learnwithak.local. (
 2011071001 ;Serial
 3600 ;Refresh
 1800 ;Retry
 604800 ;Expire
 86400 ;Minimum TTL
)
@ IN NS ehs-dns-master.lernwithak.local.
@ IN NS ehs-dns-slave.learnwithak.local.
@ IN A 172.16.4.10
@ IN A 172.16.4.11
@ IN A 172.16.4.9
@ IN A 172.16.4.8
@ IN A 172.16.4.7
@ IN A 172.16.4.6
@ IN A 172.16.4.5
@ IN A 172.16.4.4
@ IN A 172.16.5.2
@ IN A 172.16.5.3
@ IN A 172.16.5.4
ehs-dns-master  IN A 172.16.4.10
ehs-dns-standby IN A 172.16.4.11
ehs-api-2       IN A 172.16.4.9
ehs-api-1       IN A 172.16.4.8
ehs-api-lb      IN A 172.16.4.7
ehs-api-orchestration IN A 172.16.4.6
rabbit-standby  IN A 172.16.4.5
rabbit-master   IN A 172.16.4.4
db-slave        IN A 172.16.5.2
db-master       IN A 172.16.5.3
ehs-ldap        IN A 172.16.5.4

3. Start the DNS service

Enable and start DNS service:
systemctl enable named
systemctl start named

4. Firewall Configuration

We must allow the DNS service default port 53 through firewall.
Add the following lines in /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT

5. Restart Firewall

Run the following command
sudo systemctl restart iptables

6. Configuring Permissions, Ownership, and SELinux

Run the following commands one by one:
chgrp named -R /var/named
chown -v root:named /etc/named.conf
restorecon -rv /var/named
restorecon /etc/named.conf

7. Test DNS configuration and zone files for any syntax errors

Check DNS default configuration file:
named-checkconf /etc/named.conf
If it returns nothing, your configuration file is valid.
Check Forward zone:
named-checkzone learnwithak.local /var/named/forward.learnwithak
Sample output:
zone learnwithak.local/IN: loaded serial 2011071001
OK
Add the DNS Server details in your network interface config file.
vi /etc/sysconfig/network-scripts/ifcfg-ens160
HWADDR=00:50:56:01:04:20
NAME=ens160
GATEWAY=172.16.4.1
DNS=172.16.4.10
DEVICE=ens160
ONBOOT=yes
USERCTL=no
BOOTPROTO=static
NETMASK=255.255.255.0
IPADDR=172.16.4.10
PEERDNS=yes
check_link_down() {
 return 1;
}
Edit file /etc/resolv.conf,
vi /etc/resolv.conf
Add the name server ip address:
nameserver    172.16.4.10
Save and close the file.
Restart network service:
systemctl restart network

8. Test DNS Server

dig ehs-dns-master.learnwithak.local
Sample Output:
; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.1 <<>> ehs-dns-master.learnwithak.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;ehs-dns-master.learnwithak.local. IN A
;; ANSWER SECTION:
ehs-dns-master.learnwithak.local. 86400 IN A 172.16.4.10
;; AUTHORITY SECTION:
learnwithak.local. 86400 IN NS ehs-dns-master.learnwithak.local.
learnwithak.local. 86400 IN NS ehs-dns-standby.learnwithak.local.
;; ADDITIONAL SECTION:
ehs-dns-standby.learnwithak.local. 86400 IN A 172.16.4.11
;; Query time: 0 msec
;; SERVER: 172.16.4.10#53(172.16.4.10)
;; WHEN: Wed Feb 22 13:15:23 UTC 2017
;; MSG SIZE rcvd: 138
Server: 172.16.4.10
Address: 172.16.4.10#53
nslookup learnwithak.local
Sample Output:
Name: learnwithak.local
Address: 172.16.4.11
Name: learnwithak.local
Address: 172.16.5.4
Name: learnwithak.local
Address: 172.16.4.9
Name: learnwithak.local
Address: 172.16.5.2
Name: learnwithak.local
Address: 172.16.4.7
Name: learnwithak.local
Address: 172.16.4.4
Name: learnwithak.local
Address: 172.16.5.3
Name: learnwithak.local
Address: 172.16.4.8
Name: learnwithak.local
Address: 172.16.4.5
Name: learnwithak.local
Address: 172.16.4.6
Name: learnwithak.local
Address: 172.16.4.10
Now the Primary DNS server is ready to use.
It is time to configure our Secondary DNS server.

Setup Secondary(Slave) DNS Server

Install bind packages using the following command:
yum install bind bind-utils -y

1. Configure Slave DNS Server

Edit file ‘/etc/named.conf’:
vi /etc/named.conf
Make the changes as shown in bold.
//
// named.conf
//
// Provided by Red Hat bind 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.
//
options {
listen-on port 53 { 127.0.0.1; 172.16.4.11; };
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; 172.16.4.0/24; };
.
.
.
.
zone "." IN {
type hint;
file "named.ca";
};
zone "learnwithak.local" IN { 
type slave; 
file "slaves/learnwithak.fwd"; 
masters { 172.16.4.10; }; 
}; 
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
 
  

2. Start the DNS Service

systemctl enable named
systemctl start named
Now the forward  zone is automatically replicated from Master DNS server to ‘/var/named/slaves/’ in Secondary DNS server.
ls /var/named/slaves/
Sample Output:
learnwithak.fwd

Comments

Popular posts from this blog

Terraform

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied. The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc. The key features of Terraform are: Infrastructure as Code : Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and

Java 8 coding challenge: Roy and Profile Picture

Problem:  Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload. Minimum dimension of the picture can be  L x L , where  L  is the length of the side of square. Now Roy has  N  photos of various dimensions. Dimension of a photo is denoted as  W x H where  W  - width of the photo and  H  - Height of the photo When any photo is uploaded following events may occur: [1] If any of the width or height is less than L, user is prompted to upload another one. Print " UPLOAD ANOTHER " in this case. [2] If width and height, both are large enough and (a) if the photo is already square then it is accepted. Print " ACCEPTED " in this case. (b) else user is prompted to crop it. Print " CROP IT " in this case. (quotes are only for clarification) Given L, N, W and H as input, print appropriate text as output. Input: First line contains  L . Second line contains  N , number of

Salt stack issues

The function “state.apply” is running as PID Restart salt-minion with command:  service salt-minion restart No matching sls found for ‘init’ in env ‘base’ Add top.sls file in the directory where your main sls file is present. Create the file as follows: 1 2 3 base: 'web*' : - apache If the sls is present in a subdirectory elasticsearch/init.sls then write the top.sls as: 1 2 3 base: '*' : - elasticsearch.init How to execute saltstack-formulas create file  /srv/pillar/top.sls  with content: base : ' * ' : - salt create file  /srv/pillar/salt.sls  with content: salt : master : worker_threads : 2 fileserver_backend : - roots - git gitfs_remotes : - git://github.com/saltstack-formulas/epel-formula.git - git://github.com/saltstack-formulas/git-formula.git - git://github.com/saltstack-formulas/nano-formula.git - git://github.com/saltstack-f