Saturday, July 25, 2020

Installation and Configuration of Master and Caching DNS Server on Ubuntu 18.04 LTS (Bionic Beaver)

1.  Download and install BIND9 software

#apt-get install bind9

By default, the BIND9 software will start running after a successful installation.  If your objective is just to set up a "Caching DNS Server," then your installation is complete already and you can proceed to testing the functionality of the DNS server in Step No. 5.  The succeeding steps below will configure the BIND9 software as a "Master DNS Server".


2.  Configure file "/etc/bind/named.conf.local" by adding the following entries:

//forward
zone "rasul.ph" IN { // Domain name
     type master; // Primary DNS
     file "/etc/bind/forward.rasul.ph.db"; // Forward lookup file
     allow-update { none; }; // Since this is the primary DNS, it should be none.
};

//reverse
zone "0.16.172.in-addr.arpa" IN { //Reverse lookup name, should match your network in reverse order
     type master; // Primary DNS
     file "/etc/bind/reverse.rasul.ph.db"; //Reverse lookup file
     allow-update { none; }; //Since this is the primary DNS, it should be none.
};


3.  Create entries in the zone and reverse lookup files (Forward & Reverse)


3.1  Create the following entries in the Zone lookup file "/etc/bind/forward.rasul.ph.db"

$TTL    604800
@       IN      SOA     ns1.rasul.ph. root.rasul.ph. (
                              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.rasul.ph.

;IP address of Name Server
ns1     IN      A       172.16.0.1

;Mail Exchanger
rasul.ph.   IN     MX   10   mail.rasul.ph.

;A – Record HostName To Ip Address

www     IN       A      172.16.0.1
mail    IN       A      172.16.0.2

clem    IN      A       172.16.0.2
mike    IN      A       172.16.0.1

rasul.ph.       IN      A       172.16.0.1

;CNAME record
;ftp     IN      CNAME   www.rasul.ph.


3.2  Create and add entries in the Reverse lookup file "/etc/bind/reverse.rasul.ph.db"

$TTL    604800
@       IN      SOA     rasul.ph. root.rasul.ph. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
;@      IN      NS      localhost.
;1.0.0  IN      PTR     localhost.

;Name Server Information

@       IN      NS     ns1.rasul.ph.

;Reverse lookup for Name Server
;1      IN      PTR    ns1.rasul.ph.

;PTR Record IP address to HostName

1     IN      PTR    www.rasul.ph.
2     IN      PTR    mail.rasul.ph.


4.  Check bind configuration syntax by issuing the command

# named-checkconf


5.  Test the DNS response from a client utility using nslookup or host as follows:


5.1  On the client computer, make changes to the name resolution resolver file "/etc/resolv.conf"

# cd /etc
# vi resolv.conf

nameserver 172.16.0.1

172.16.0.1 is the IP address of the nameserver where BIND9 is installed


5.2  Test the name resolution using nslookup

$nslookup www.rasul.ph

The response should indicate 172.16.0.1

$ nslookup 172.16.0.1

The response should indicate www.rasul.ph


5.3  Alternatively, you can also test name resolution using host command

$ host www.rasul.ph

The response should indicate 172.16.0.1

$ host 172.16.0.1

The response should indicate www.rasul.ph

At this point, your master DNS server installation is complete. 


6.  On occasions, there may be a need for you to restart, stop and start the BIND9 software.  This can be achieved by issuing the following command:

To restart the server, issue the command

# systemctl restart bind9.service


To stop the server, issue the command

# systemctl stop bind9.service


To start the server, issue the command

# systemctl start bind9.service


7.  The BIND9 software runs under the process called "named".  To see if the process is running, issue the command

# ps ax | grep named

You should be able to see the "named" process as running as follows:

11305 ?        Ssl    0:00 /usr/sbin/named -f -u bind
11313 pts/0    S+     0:00 grep --color=auto named


If the process is not running, display will just be as follows:

11219 pts/0    S+     0:00 grep --color=auto named


8.  Should there be a need for you to uninstall the BIND9 software, issue the command after stopping the BIND9 service as follows:

# systemctl stop bind9.service
# apt-get remove bind9

This will uninstall the BIND9 software.




No comments: