Setting Up DNS Server On CentOS 7

The Domain Name Service (DNS) is an internet service that converts domain names into their corresponding IP Addresses and vice versa.

Any computer on the internet can maintain a file that manually associates IP addresses with domain names. On Linux and Unix systems, this file is called the /etc/hosts file. Here you can enter the IP Addresses and domain names of computers you commonly access.

Using this method, however, each computer needs a complete listing of all other computers on the Internet, and this listing must be updated constantly.

The DNS has been implemented to deal with the task of translating the domain name of any computer on the Internet to its IP Address.

Types DNS Servers

There are several kinds of DNS Servers, each performs different types of tasks under the domain Name Service. These are

Master Server: This is the primary DNS server for a zone. Each network must have at least one master server which is responsible for resolving names on the network.

Slave Server: These are references to other dns servers for your network to help carry the workload. A slave DNS server automatically copies its configuration file, including all zone files from the master DNS server.

Forwarder Server: A server that forwards unresolved DNS requests to outside DNS Servers and can be used to keep other servers as a local network hidden from the Internet.

Caching only Server: Caches DNS information it receives from DNS Server and uses it to resolve the local requests.

Environment.

DNS Server Details:
Operating System: CentOS 7 minimal server
Hostname: centos-vm1
IP Address: 192.168.2.122/24

Client Details:
Operating System: CentOS 7 minimal server
Hostname: centos-vm2
IP Address: 192.168.2.123/24

Operating System: CentOS 7 minimal server
Hostname: centos-vm3
IP Address: 192.168.2.124/24

DNS Server Installation:
1. Install bind and bind-utils packages on your server.

# yum install bind bind-utils -y

2. Configure DNS Server

Edit ‘/etc/named.conf’ file.

# vi /etc/named.conf

Update the lines as shown in bold:

listen-on port 53 { 127.0.0.1; 192.168.2.122;}; ### Master DNS IP ###
# listen-on-v6 port 53 { ::1; }; ### Comment ###
allow-query { localhost; 192.168.2.0/24;}; ### IP Range ###

Add the zone details

zone "darole.org" IN {
type master;
file "forward.darole";
allow-update { none; };
};
zone "2.168.192.in-addr.arpa" IN {
type master;
file "reverse.darole";
allow-update { none; };
};

3. Create Zone files
Create forward and reverse zone files which we mentioned in the ‘/etc/named.conf’ file.

3.1 Create Forward Zone

Create forward.darole file in the ‘/var/named’ directory.

There are some special keywords for Zone Files

A – A record
NS – Name Server
MX – Mail for Exchange
CNAME – Canonical Name

# vi /var/named/forward.darole
@   IN  SOA     centos-vm1.darole.org. root.darole.org. (
        2011071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
; Name Server Information
@       IN  NS          centos-vm1.darole.org.
@       IN  NS          centos-vm3.darole.org.

; IP Address of Name Server
centos-vm1      IN  A   192.168.2.122

; Mail exchanger
@       IN  MX  10      centos-vm2.darole.org.

; A - Record Hostname to IP Address
;@       IN  A           192.168.2.122
centos-vm2       IN  A   192.168.2.123
centos-vm3       IN  A   192.168.2.124

; CNAME record
ftp     IN      CNAME     centos-vm3.darole.org.

3.2 Create Reverse Zone

Create reverse.darole file in the ‘/var/named’ directory.

# vi /var/named/reverse.darole
$TTL 86400
@ IN SOA centos-vm1.darole.org. root.darole.org. (
                2011071001 ;      Serial
               3600 ;                 Refresh
              1800 ;                  Retry
              604800 ;              Expire
              86400 ;               Minimum TTL
)
@ IN NS centos-vm1.darole.org.
@ IN PTR darole.org.
centos-vm1 IN A 192.168.2.122
centos-vm2 IN A 192.168.2.123
centos-vm3 IN A 192.168.2.124
122 IN PTR centos-vm1.darole.org.
123 IN PTR centos-vm2.darole.org.
124 IN PTR centos-vm3.darole.org.

4. 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 darole.org /var/named/forward.darole

# named-checkzone darole.org /var/named/reverse.darole

5. Enable and start DNS service:

# systemctl enable named
# systemctl start named

6. Update DNS entry in /etc/resolv.conf

Add the name server ip address:

# vi /etc/resolv.conf
nameserver 192.168.1.122

Restart network service:
# systemctl restart network

7. Test DNS records
# nslookup centos-vm1.darole.org
# nslookup centos-vm2.darole.org
# nslookup centos-vm3.darole.org
# nslookup 192.168.2.122
# nslookup 192.168.2.123
# nslookup 192.168.2.124

To check the cname and mx record.

[root@centos-vm1 named]# nslookup ftp.darole.org
Server:         192.168.2.122
Address:        192.168.2.122#53
ftp.darole.org  canonical name = centos-vm3.darole.org.
Name:   centos-vm3.darole.org
Address: 192.168.2.124
[root@centos-vm1 named]# nslookup
> set type=mx
> darole.org
Server:         192.168.2.122
Address:        192.168.2.122#53
darole.org      mail exchanger = 10 centos-vm2.darole.org.
>
exit
[root@centos-vm1 named]#

 


 

 

 

No comments:

Post a Comment