dns server linux

22
Guide for setting up a DNS Server in Red Hat / CentOS / Fedora The following guide will help you setup your very own fully functional local DNS Server for your Linux Operating Systems. I have also prepared a GUIDE for setting up a CentOS based LDAP server. you can view that HERE In this guide, we are going to use CentOS as the base OS for setting up our DNS server, however the same steps should be applicable on most Linux OS platforms as well such as Red Hat, Fedora etc. The diagram below depicts the layout of our test domain a.k.a "cloud.com". We are going to set up a Primary / Master DNS along with a Client to test whether the DNS was successfully setup or not.

Upload: anb

Post on 11-Jul-2016

302 views

Category:

Documents


5 download

DESCRIPTION

DNS Server Linux

TRANSCRIPT

Page 1: DNS Server Linux

Guide for setting up a DNS Server in Red Hat / CentOS / FedoraThe following guide will help you setup your very own fully functional local DNS Server for your Linux Operating Systems. 

I have also prepared a GUIDE for setting up a CentOS based LDAP server. you can view that HERE

In this guide, we are going to use CentOS as the base OS for setting up our DNS server, however the same steps should be applicable on most Linux OS platforms as well such as Red Hat, Fedora etc.

The diagram below depicts the layout of our test domain a.k.a "cloud.com". We are going to set up a Primary / Master DNS along with a Client to test whether the DNS was successfully setup or not.

Machine Details:

Primary / Master DNS Server:OS: CentOS 6.3 64 BitHost name: masterdns.cloud.com  IP: 192.168.50.128Subnet: 255.255.255.0

Secondary / Fail Safe DNS Server:OS: CentOS 6.3 64 BitHost name: slavedns.cloud.com  IP: 192.168.50.129Subnet: 255.255.255.0

Page 2: DNS Server Linux

Test Client Server:OS: CentOS 6.3 64 BitHost Name: client.cloud.com IP: 192.168.50.130Subnet: 255.255.255.0

Setting up the Master DNS Server:

First, we need to install the DNS software. In this case, we are using Bind. Bind is a popular Linux-based DNS server and is widely used all over the world.Execute the following command in your Master DNS server:NOTE: The following commands have been executed using root privileges.# yum install bind*

Once installed, we configure the DNS Server. To do this, we need to edit a configuration file with some parameters: # vi /etc/named.conf

Page 3: DNS Server Linux

Make ONLY the changes that are highlighted below:

NOTE: Replace the Master DNS Server IP address with your own Master Server's IP address. If you plan to setup a Secondary DNS, then fill in the Slave DNS IP Address as shown below, else ignore the setting. Provide your Forward and Reverse Lookup zones as required.   //// 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; 192.168.50.128;}; ### Provide your 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.50.0/24;}; ### IP Address Range ### allow-transfer{ localhost; 192.168.50.129;}; ### Slave DNS IP Address ###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";};logging {        channel default_debug {                file "data/named.run";                severity dynamic;        };};zone "." IN {type hint;file "named.ca";};### Forward Lookup Zone ###zone"cloud.com" IN {type master;

Page 4: DNS Server Linux

file "forward.cloud";allow-update { none; };};### Reverse Lookup Zone ###zone"50.168.192.in-addr.arpa" IN {type master;file "reverse.cloud";allow-update { none; };};include "/etc/named.rfc1912.zones";include "/etc/named.root.key";

Page 6: DNS Server Linux

Once edited, we now need to create forward and reverse zone files which we mentioned in the ‘/etc/named.conf’ file.

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

NOTE: Make ONLY the changes that are highlighted below: # vi /var/named/forward.cloud $TTL 86400@   IN  SOA     masterdns.cloud.com. root.cloud.com. (        2011071001  ;Serial        3600        ;Refresh        1800        ;Retry        604800      ;Expire        86400       ;Minimum TTL)@       IN  NS          masterdns.cloud.com.@       IN  NS          slavedns.cloud.com.@       IN  A           192.168.50.128@       IN  A           192.168.50.129@       IN  A           192.168.50.130masterdns       IN  A   192.168.50.128slavedns    IN  A   192.168.50.129client          IN  A   192.168.50.130

Similarly, create reverse.cloud file in the ‘/var/named’ directory.

Page 7: DNS Server Linux

NOTE: Make ONLY the changes that are highlighted below:

# vi /var/named/reverse.cloud   $TTL 86400@   IN  SOA     masterdns.cloud.com. root.cloud.com. (        2011071001  ;Serial        3600        ;Refresh        1800        ;Retry        604800      ;Expire        86400       ;Minimum TTL)@       IN  NS          masterdns.cloud.com.@       IN  NS          slavedns.cloud.com.@       IN  PTR         cloud.com. masterdns       IN  A   192.168.50.128slavedns    IN  A   192.168.50.129client          IN  A   192.168.50.130 128     IN  PTR         masterdns.cloud.com.129     IN  PTR         slavedns.cloud.com.130     IN  PTR         client.cloud.com.

If all's gone well, then we are now ready to start the DNS service:

Page 8: DNS Server Linux

# service named start

# chkconfig named on

You can test the DNS configuration and the Zone files for any errors by running the following commands:

# named-checkconf /etc/named.conf   # named-checkzone unixmen.local /var/named/forward.cloud # named-checkzone unixmen.local /var/named/reverse.cloud 

 

You can test your DNS server by running the following command. You should receive the output with a "NOERROR" status as shown:

# dig masterdns.cloud.com

Page 10: DNS Server Linux

Setting up the Slave DNS Server (OPTIONAL):

Once our Master DNS is set up, setting up a secondary or slave DNS Server is optional, but its always a good practice to have one in place. Installing a Slave DNS server is no different for that of the Master, just a few configurations differ.

To get started, first install bind on the slave DNS Server machine:

# yum install bind*

Once installed, we configure the DNS Server. To do this, we need to edit a configuration file with some parameters:

# vi /etc/named.conf

Make ONLY the changes that are highlighted below:

//// 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; 192.168.50.129;}; ### Provide your Slave 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.50.0/24;}; ### IP Address Range ### 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";};logging {        channel default_debug {                file "data/named.run";                severity dynamic;        };};zone "." IN {

Page 11: DNS Server Linux

type hint;file "named.ca";};### Forward Lookup Zone ###zone"cloud.com" IN {type slave;file "slaves/cloud.fwd";masters { 192.168.1.100; };masters {192.168.50.128;};};### Reverse Lookup Zone ###zone"50.168.192.in-addr.arpa" IN {type slave;file "slaves/cloud.rev";masters {192.168.50.128;};};include "/etc/named.rfc1912.zones";include "/etc/named.root.key"; Once done, save the file and exit the editor.

Page 13: DNS Server Linux

If all's gone well, then we are now ready to start the DNS service:# service named start# chkconfig named on

You can see that once the service is started, the Forward and Reverse lookup zone files are automatically copied form the Master DNS to /var/named/slaves folder in the Slave DNS Server.

You can test your DNS server by running the following command. You should receive the output with a "NOERROR" status as shown:# dig slavedns.cloud.com

Page 14: DNS Server Linux

# vi /etc/named.conf  // // 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; 192.168.1.101;}; 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;}; 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"; }; logging {         channel default_debug {                 file "data/named.run";                 severity dynamic;         }; }; zone "." IN { type hint; file "named.ca"; }; zone"unixmen.local" IN { type slave; file "slaves/unixmen.fwd"; masters { 192.168.1.100; }; }; zone"1.168.192.in-addr.arpa" IN { type slave; file "slaves/unixmen.rev"; masters { 192.168.1.100; }; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; - See more at: http://www.unixmen.com/dns-server-installation-step-by-step-using-centos-6-3/#sthash.y1dxQ5YU.dpuf

Setting up the Clients:

Once our Master DNS and Slave DNS is set up, we can now configure our Linux Clients against this Domain:

In all your 'Client' machines, simply add the following entries in the following file:# vi /etc/resolv.confsearch cloud.com### Master DNS ### search 192.168.50.128### Slave DNS ### search 192.168.50.129

Save the file and exit the editor. You should now be able to see your 'Client' Machine's FQDN as well as shown below:NOTE: You will have to manually add each Client in your Master DNS forward and reverse files. This will help in providing a FQDN to your clients.

Page 15: DNS Server Linux

Thats all for now.. hope this tutorial guides you to set up your DNS successfully..