Wednesday, 7 January 2015

Quick Start: Setup CentOS 7 as a DNS Server

Quick Start: Setup CentOS 7 as a DNS Server

In this tutorial, I'll be showing you simply steps using which you can create and configure a functional DNS Server on your CentOS 7 system.


System Details:
Base OS:        CentOS 7 64 Bit (Minimal ISO)
HOSTNAME:  master.cloud.com
IPADDRESS: 192.168.0.15

Steps:

First of all, make sure your system has a static IP address assigned to it and a fully qualified domain name.



Next, install the DNS packages:

# yum install bind bind-utils



Edit the "named.conf" file and edit the content as shown below:

# vi /etc/named.conf



# Replace the content in RED with your values
options {
listen-on port 53 { 127.0.0.1; 192.168.0.15;}; ## DNS Server 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.0.0/24;}; # IP Subnet
 





# Add the following lines before the include statement as shown
zone "cloud.com" IN { 
type master; 
file "forward.cloud"; 
allow-update { none; }; 
}; 
zone "0.168.192.in-addr.arpa" IN { 
type master; 
file "reverse.cloud"; 
allow-update { none; }; 
};



Save the file and exit the editor.
Next, we create the Zone files. There will be two files created, one for the forward lookup and one for the reverse lookup. These files are created in the /var/named directory and their names should be same as mentioned in the named.conf file (Earlier steps)

Forward Zone Lookup File:

# vi /var/named/forward.cloud



Add the following content as shown. Replace the content marked in RED with your matching requirements.

$TTL 86400 
@ IN SOA master.cloud.com. root.cloud.com. ( 
             2011071001 ;Serial 
             3600 ;Refresh 
             1800 ;Retry 
             604800 ;Expire 
             86400 ;Minimum TTL  
       ) 
@    IN     NS     master.cloud.com
@    IN     A       192.168.0.15 
@    IN     A       192.168.0.102 
@    IN     A       192.168.0.103 
master       IN       A       192.168.0.15 
client1       IN       A       192.168.0.101 
client2       IN       A       192.168.0.102

Save and exit the editor.



Reverse Zone Lookup File:

# vi /var/named/reverse.cloud




$TTL 86400 
@ IN SOA master.cloud.com. root.cloud.com. ( 
             2011071001 ;Serial 
             3600 ;Refresh 
             1800 ;Retry 
             604800 ;Expire 
             86400 ;Minimum TTL  
       ) 
@    IN     NS     master.cloud.com
@    IN     PTR   cloud.com
master       IN       A       192.168.0.15 
client1       IN       A       192.168.0.101 
client2       IN       A       192.168.0.102
15       IN     PTR   master.cloud.com
101     IN     PTR   client1.cloud.com
102     IN     PTR   client2.cloud.com

Save and exit the editor.


Enable and start the DNS service:

# systemctl enable named

# systemctl start named



Enable the ports on the Firewall and reload the firewall

# firewall-cmd --permanent --add-port=53/tcp

# firewall-cmd --reload



Verify your DNS:

Check DNS default configuration file for errors:

# named-checkconf /etc/named.conf



Next, check both the forward and reverse lookup files for any errors as well.

# named-checkzone cloud.com /var/named/forward.cloud



# named-checkzone cloud.com /var/named/reverse.cloud


Once checked, modify the network interface file and add the DNS details as shown below:

DNS1=192.168.0.15

NOTE: In my case, I am using multiple DNSs. You can assign multiple DNS values using as shown in the image below.



Alternatively, you can even add the DNS entry in the /etc/resolv.conf file as well for name resolution.

# vi /etc/resolv.conf

nameserver 192.168.0.15



Restart your network to apply the changes

# systemctl restart network



Test the DNS:

Run the following commands to verify whether the DNS can resolve the hostnames correctly or not.

# dig master.cloud.com



You can alternatively run nslookup to verify your Zones

# nslookup cloud.com




There you have it.. a simple and easy to use DNS server on a CentOS 7 System.. Hope this post helps you out! Stay tuned for a lot more coming your way soon!!

Cheers.




1 comment :

hridoy said...

Nice direction thanks..

Post a Comment