Setup BIND DNS Server on CentOS 7

Setup BIND DNS Server on CentOS 7

This tutorial provides an example how to Setup BIND DNS Server on CentOS 7.
This example is suited for secure private networks behind a gateway.

BIND Installation

Easiest way is to Setup BIND DNS Server from CentOS Default Repositories:

yum install bind bind-utils

BIND Configuration

Edit the main config file:

vi /etc/named.conf

Find the ‘options’ section and:

add your DNS Server IP Address to the listen directive:

listen-on port 53 { 127.0.0.1; 192.168.1.1; };

Enable queries from all clients

– this is a secure network so we can just use ‘any’:

allow-query { any; };

Create Zones config File and include it in main config

Create a file called ‘/etc/named/named.conf.local’ and edit the domain name to fit your environment:

zone "example.domain.com" {
    type master;
    file "/etc/named/zones/example.domain.com";
};

zone "1.168.192.in-addr.arpa" {
    type master;
    file "/etc/named/zones/db.192.168.1";  # 192.168.1.0/24 subnet
};

Include the new file in the end of our main config file ‘/etc/named.conf’:

include "/etc/named/named.conf.local";

Create Zones

Forward Zone

Create a file ‘/etc/named/zones/example.domain.com’:

$TTL 604800
@       IN      SOA     example.domain.com. admin.example.domain.com. (
        9               ; Serial
        604800          ; Refresh
        86400           ; Retry
        2419200         ; Expire
        604800 )        ; Negative Cache TTL

; NS records
@       IN      NS      ns.example.domain.com.

; NS A records
ns.example.domain.com.      IN      A       192.168.1.1

; Other Hosts A records
examplehost.example.domain.com.       IN      A       192.168.1.10

Reverse Zone

Create a file ‘/etc/named/zones/db.192.168.1’:

$TTL 604800
@       IN      SOA     example.domain.com. admin.example.domain.com. (
        9               ; Serial
        604800          ; Refresh
        86400           ; Retry
        2419200         ; Expire
        604800 )        ; Negative Cache TTL
; name servers
@       IN      NS      ns.example.domain.com.

; PTR Records
1     IN      PTR     ns.example.domain.com.   ; 192.168.1.1
10    IN      PTR     examplehost.example.domain.com.   ; 192.168.1.10

Test Config Files

You can test for syntax errors with the following command:

named-checkconf

BIND start and enable for auto-start on boot

Run the BIND service:

systemctl start named

Start BIND with system boot:

systemctl enable named

– If you need to edit the config after you started the service don’t forget to update the ‘Serial’ directive in the zone file.

This concludes the basic Setup of BIND DNS Server.
Enjoy.

1 thought on “Setup BIND DNS Server on CentOS 7

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.