How to Install and configure DNS on Ubuntu 20.04.

A DNS server is a system server that check a database of Ip address and clients.  It provides to resolve those names to public ip address as requested. DNS servers run software and communicate with each other using protocols.

Domain Name Service (DNS) is an Internet service that contains IP addresses and fully qualified domain names (FQDN) to other. Computers that run DNS are called name servers.

Install DNS

Update the System

apt-get update

Install the required packages

apt-get install -y bind9 bind9utils bind9-doc dnsutils

Start & Stop bind9 service

systemctl start bind9
systemctl stop bind9

Check Bind9 status

systemctl status bind9

Here is the command output.

Fig 1

 

Configure DNS Server

  • Go to DNS server main directory.
cd /etc/bind
  • At bind directory, we have Two zone file: one is global DNS conf file named.conf & second is local DNS config file named.conf.local.
  • We needs to create forward and reverse zones.
  • Open named.conf.local file.
vim named.conf.local
  • To create a zone & add the following values for forward zone.
zone "zone-name.local" IN { // Domain name
    
      type master; // Primary DNS

     file "/etc/bind/forward.zone-name.local.db"; // Forward lookup file

     allow-update { none; }; // Since this is the primary DNS, it should be none.
     
    
};

 

  • Now Add the following value in same file for reverse zone.If network is 198.16.10.0, the name will be reversed as in 10.16.198
zone "10.16.198.in-addr.arpa" IN { //Reverse lookup name, should match your network in reverse order

     type master; // Primary DNS

     file "/etc/bind/reverse.zone-name.local.db"; //Reverse lookup file

     allow-update { none; }; //Since this is the primary DNS, it should be none.

    

};

 

Configure Bind DNS zone lookup files

  • DNS records for Both forward & Reverse zone are under zone lookup files.
  • Configure Forward zone lookup file.
  • Copy the db.local file to a  /etc/bind/forward.zone-name.local.db file.
cp /etc/bind/db.local /etc/bind/forward.zone-name.local.db
  • Open the /etc/bind/forward.zone-name.local.db & mention the following lines.
$TTL    604800
@       IN      SOA     ns1.zone-name.local. root.ns1.zone-name.local. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
;@      IN      NS      localhost.
;@      IN      A       127.0.0.1
;@      IN      AAAA    ::1

;Name Server Information

@        IN      NS      ns1.zone-name.local.

;IP address of Name Server

ns1     IN      A       ip-address

;Mail Exchanger

zone-name.local.   IN     MX   10   mail.zone-name.local.

;A – Record HostName To Ip Address

www     IN       A      ip-address1
mail    IN       A      ip-address2

;CNAME record

ftp     IN      CNAME   www.zone-name.local.

 

where

  • SOA – Start of Authority.
  • NS – Name Server.
  • A – A record.
  • MX – Mail for Exchange.
  • CN – Canonical Name.

 

  • Configure Reverse zone lookup file.
  • Copy db.127 to a reverse.computingforgeeks.local.db file.
cp /etc/bind/db.127 /etc/bind/reverse.zone-name.local.db
  • Open the /etc/bind/reverse.zone-name.local.db & mention the following lines.
;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA    zone-name.local. root.zone-name.local. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;

;Name Server Information

@       IN      NS     ns1.zone-name.local.
ns1     IN      A       ip-address

;Reverse lookup for Name Server

2      IN      PTR    ns1.zone-name.local.

;PTR Record IP address to HostName

3     IN      PTR    www.zone-name.local.
4     IN      PTR    mail.zone-name.local.

 

Where

  • PTR – Pointer.
  • SOA – Start of Authority.

Restart & Enable BIND service.

systemctl restart bind9
systemctl enable bind9

Access DNS server

  • On client machine, change the DNS server to our deployed server. For example: 198.16.10.2
echo "nameserver 198.16.10.2" >> /etc/resolv.conf
  • Now run dig command.The dig command is used to get the information about a domain name such as DNS server, domain IP , MX records.
dig www.zone-name.local 
  • Check the reverse DNS.
dig -x ip-address

 

2 responses to “How to Install and configure DNS on Ubuntu 20.04.”

    • Gracias por la respuesta.
      Seguramente seguiremos publicando publicaciones.

      Si te gusta esta publicación, comparte también la misma en tu red.

Leave a Reply

Your email address will not be published.