How to Install and Configure DNS Server in Linux – Centos/ubuntu

Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified domain names (FQDN) and vice versa.

BIND stands for Berkley Internet Naming Daemon.

BIND is the most common program used for maintaining a name server on Linux.

In this tutorial, we will explain how to install and configure a DNS server.

Install Bind

Install the bind9 package using the appropriate package management utilities for your Linux distributions.

On Debian/Ubuntu flavors, do the following:

 sudo apt-get install bind9

On Redhat/CentOS/Fedora flavors, do the following:

 yum install bind9

All the DNS configurations are stored under /etc/bind directory. The primary configuration is /etc/bind/named.conf which will include other needed files. The file named /etc/bind/db.root describes the root nameservers in the world.

IPv4 Mode

Before continuing, let’s set BIND to IPv4 mode. On both servers, edit the bind9 service parameters file:

sudo vi /etc/default/bind9

Add “-4” to the OPTIONS variable. It should look like the following – /etc/default/bind9

OPTIONS="-4 -u bind"

Save and exit.

Now that BIND is installed, let’s configure the primary DNS server.

Creating Zones entries

Firstly we will create a forward zone entry in /etc/named.conf for our domain webhostingnoida.com. Add the following lines in named.conf

zone "webhostingnoida.com" IN {
type master;
file "fwd.webhostingnoida.com.db";
allow-update { none; };
};

Here, ‘webhostingnoida.com’ is the Domain name,

‘master’ is the Primary DNS,

fwd.webhostingnoida.com.db is the Forward lookup file,

‘allow-update’ will be none, its the primary DNS.

Similarly, we will now create an entry for reverse zone as well in”named.conf”

zone "1.168.192.in-addr.arpa" IN {
type master;
file "1.168.192.db";
allow-update { none; };
};

Here,

1.168.192.in-addr.arpa  is Reverse lookup name,

master is for Primary DNS,

1.168.192.db is the reverse lookup file,

allow-update – will be set to none, since this is the primary DNS.

Our configuration for “named.conf” is complete & next we will create zone files for our BIND server.

Creating zone files

We will first create our forward zone file i.e “fwd.webhostingnoida.com.db” in “/var/named” folder and then will make the following entries in it

$TTL 86400
@ IN SOA primary.webhostingnoida.com. root.webhostingnoida.com. (
2014112511 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
;Name Server Information
@ IN NS primary.webhostingnoida.com.
;IP address of Name Server
primary IN A 192.168.1.100
;Mail exchanger
webhostingnoida.com. IN MX 10 mail.webhostingnoida.com.
;A - Record HostName To Ip Address
www IN A 192.168.1.105
mail IN A 192.168.1.120
;CNAME record
ftp IN CNAME www.webhostingnoida.com.

Similarly, we will create reverse zone file named “1.168.192.db” in “/var/named” folder with the following content

vi /var/named/1.168.192.db
$TTL 86400
@ IN SOA dns.ltechlab.com. root.ltechlab.com. (
2014112511 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
;Name Server Information
@ IN NS dns.ltechlab.com.
;Reverse lookup for Name Server
8 IN PTR dns.ltechlab.com.
;PTR Record IP address to HostName
105 IN PTR www.ltechlab.com.
120 IN PTR mail.ltechlab.com.

 

After creating these zone files, we will restart our BIND server

service named restart or
systemctl restart named.service

Now, we will verify our zone files.

Test the DNS server

Now we have configured the DNS server for our domain. We will test our DNS server by pinging mail.webhostingnoida.com from web.webhostingnoida.com.

If the ping is success, then we have configured the DNS successfully.

You can also use nslookup and dig to test DNS servers.

On web.webhostingnoida.com server, add the following to /etc/resolv.conf

nameserver 10.42.0.83

Now ping, mail.webhostingnoida.com, which should resolve the address appropriately from the DNS server that we just configured.

$ ping mail.thegeekstuff.net

PING mail.thegeekstuff.net (10.42.0.70) 56(84) bytes of data.
64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=1 ttl=64 time=0.482 ms
64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=2 ttl=64 time=0.532 ms

Hope you like this blog