How to Install & Configure DNS on Ubuntu 20.04 & 22.04

 https://www.SET_your_domain_name.com/install-configure-bind-9-dns-server-ubuntu-debian/

 sudo apt install -y bind9 bind9utils bind9-doc dnsutils
sudo nano /etc/bind/named.conf.options

acl internal-network {
192.168.0.0/23;
};

options {
        directory "/var/cache/bind";
        allow-query { localhost; internal-network; 192.168.0.0/23; localnets; };
        allow-transfer { localhost; };
        forwarders { 1.1.1.1; 8.8.4.4; };
        recursion yes;
        dnssec-validation auto;
        listen-on-v6 { any; };
};



sudo vi named.conf.local

zone "SET_your_domain_name.local" IN {
        type master;
        file "/etc/bind/forward.SET_your_domain_name.local";
        allow-update { none; };
};
zone "0.166.103.in-addr.arpa" IN {
        type master;
        file "/etc/bind/reverse.SET_your_domain_name.local";
        allow-update { none; };
};


sudo cp db.local forward.SET_your_domain_name.local

$TTL 604800
@ IN SOA primary.SET_your_domain_name.local. root.primary.SET_your_domain_name.local. (
         2022072651 ; Serial
         3600 ; Refresh
         1800 ; Retry
         604800 ; Expire
         604600 ) ; Negative Cache TTL
;Name Server Information
@ IN NS primary.SET_your_domain_name.local.

;IP address of Your Domain Name Server(DNS)
primary IN A 192.168.0.9

;Mail Server MX (Mail exchanger) Record
SET_your_domain_name.local. IN MX 10 mail.SET_your_domain_name.local.

;A Record for Host names
www IN A 192.168.0.50
mail IN A 192.168.0.60

;CNAME Record
ftp IN CNAME www.SET_your_domain_name.local.



$ sudo cp db.127 reverse.SET_your_domain_name.local
$ sudo vi /etc/bind/reverse.SET_your_domain_name.local

$TTL 86400
@ IN SOA SET_your_domain_name.local. root.SET_your_domain_name.local. (
         2022072752 ;Serial
         3600 ;Refresh
         1800 ;Retry
         604800 ;Expire
         86400 ;Minimum TTL
)
;Your Name Server Info
@ IN NS primary.SET_your_domain_name.local.
primary IN A 192.168.0.9
;Reverse Lookup for Your DNS Server
40 IN PTR primary.SET_your_domain_name.local.
;PTR Record IP address to HostName
50 IN PTR www.SET_your_domain_name.local.
60 IN PTR mail.SET_your_domain_name.local.



Update the following parameter in ‘/etc/default/named ‘ file, so that dns service starts listening on IPv4

OPTIONS="-u bind -4"

Now all we have to do is to start and enable the BIND service to implement the changes made,

$ sudo systemctl start named
$ sudo systemctl enable named
View the bind service status, run

$ sudo systemctl status named

Note : In case OS firewall is running on your bind server then execute the below command to allow 53 port

$ sudo ufw allow 53
Rule added
Rule added (v6)
$


$ sudo named-checkconf /etc/bind/named.conf.local

If there is no syntax error in your bind configuration file, then it should return to shell without showing any errors.

To cross verify the syntax your forward and reverse lookup zone files , use the command “named-checkzone”, example is shown below:

$ sudo named-checkzone npcn.local /etc/bind/forward.npcn.local

zone SET_your_domain_name.local/IN: loaded serial 2022072651
OK
$
$ sudo named-checkzone npcn.local /etc/bind/reverse.npcn.local
zone SET_your_domain_name.local/IN: loaded serial 2022072752
OK
$
Step 4) Test DNS server with dig & nslookup
To test out our BIND 9 DNS server, we will use another Ubuntu machine & will change its DNS to point out our DNS server. To change the DNS server, open ‘/etc/resol.conf’ & make the following DNS entry,

SET_your_domain_name@IPCORE:~$ sudo vi /etc/resolv.conf
search SET_your_domain_name.local
nameserver 192.168.0.40

save the file & exit. We now have our client ready with DNS pointing to our server. We will now use a CLI tool called ‘dig‘ command , which is used to get find out DNS & its related information. Execute the following command from terminal,

SET_your_domain_name@IPCORE:~$ dig primary.npcn.local

nano /etc/hosts
add
103.166.150.9 mcsol.local

SET_your_domain_name@IPCORE:~$ dig -x 192.168.0.9


Also we can run ‘nslookup‘ command against our DNS server to confirm the output of dig command,

SET_your_domain_name@IPCORE:~$ nslookup primary.npcn.local

SET_your_domain_name@IPCORE:~$ sudo apt install dnsutils -y

Comments

Popular posts from this blog

Installing NFSEN & NFDUMP on Ubuntu and Next integrate with LibreNMS

IP Core Networks | Your Education, Your Choice

How to Install & Integrate Oxidized Into LibreNMS