10.2 C
Texas

How To Install and Configure Master BIND DNS Server On Ubuntu 20.04

Today we are going to learn that how to install and configure Master BIND DNS server on Ubuntu 20.04. As you all know that DNS provides the functionality of converting human readable domains to computer readable IP’s & vice versa. So, it helps to translate the domain names. Here we’ll see that how we can install & configure Master BIND DNS Server On Ubuntu 20.04.

Before proceeding towards the installation procedure, make sure your system has a static IP configured.

Step 1: Update Your System

Before installing any new package, make sure your system is up-to date.

sudo apt -y update

Step 2: Download & Install the BIND DNS Server

- Advertisement -

Run the below command to install the bind dns server and required packages.

sudo apt install -y bind9 bind9utils bind9-doc dnsutils

Step 3: Configure DNS Server

Main configuration directory of DNS is located at /etc/bind.

Global DNS configuraiton file can be found at /etc/bind/named.conf that can’t be used for local DNS. For local DNS, /etc/bind/named.conf.local is used.

Create Zones

Edit the local DNS file with your favourite editor.

sudo nano /etc/bind/named.conf.local

And then create forward & reverse zones for your domain. Here I’ll create for osradar.com as seen below:

zone "osradar.local" IN { // Domain name

type master; // Primary DNS

file "/etc/bind/forward.osradar.local.db"; // Forward lookup file

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

};

That was for the forward zone. Now, we’ll add for reverse zone.

zone "10.16.172.in-addr.arpa" IN { //Reverse lookup name, should match your network in reverse order

type master; // Primary DNS

file "/etc/bind/reverse.osradar.local.db"; //Reverse lookup file

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

};

10.16.172.in-addr.arpa is the zone name of reverse DNS. (If network is 172.16.10.0, the name will be reversed as in 10.16.172).

Step 4: Configure Bind DNS Zone Lookup Files

As described earlier, the zone lookup files have the DNS records of the forward & reverse zones. So, we’ll configure them.

For Forward Zone Lookup File

Now, copy the sample forward zone lookup file to the file called forward.osradar.local.db located at /etc/bind directory.

sudo cp /etc/bind/db.local /etc/bind/forward.osradar.local.db

Now, edit the above file.

sudo nano /etc/bind/forward.osradar.local.db
$TTL 604800
@ IN SOA ns1.osradar.local. root.ns1.osradar.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.osradar.local.

;IP address of Name Server

ns1 IN A 172.16.10.2

;Mail Exchanger

osradar.local. IN MX 10 mail.osradar.local.

;A – Record HostName To Ip Address

www IN A 172.16.10.3
mail IN A 172.16.10.4

;CNAME record

ftp IN CNAME www.osradar.local.
For Reverse Zone Lookup File

Simply perform the above actions for reverse zone lookup file.

sudo cp /etc/bind/db.127 /etc/bind/reverse.osradar.local.db

And then modify the content.

sudo nano /etc/bind/reverse.osradar.local.db
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA osradar.local. root.osradar.local. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;

;Name Server Information

@ IN NS ns1.osradar.local.
ns1 IN A 172.16.10.2

;Reverse lookup for Name Server

2 IN PTR ns1.osradar.local.

;PTR Record IP address to HostName

3 IN PTR www.osradar.local.
4 IN PTR mail.osradar.local.

Step 5: Verify Bind DNS Syntax

Hit the given command to verify the syntax of bind DNS it’ll return to the shell if everything is ok.

sudo named-checkconf

Fire the below commands to check the syntax for forward & reverse zones respectively.

sudo named-checkzone osradar.local /etc/bind/forward.osradar.local.db
sudo named-checkzone 10.16.172.in-addr.arpa /etc/bind/reverse.osradar.local.db

You’ll see the similar output respectively.

#####forward zone file
OK
#####reverse zone file
zone 10.16.172.in-addr.arpa/IN: loaded serial 1
OK

Finally, restart & enable BIND services.

sudo systemctl restart bind9
sudo systemctl enable bind9

Step 6: Test DNS Server On Ubuntu 20.04

We can change the DNS server on any of client machine to our newly created server. Every OS has different DNS settings. In Ubuntu type

sudo echo "nameserver 172.16.10.2" >> /etc/resolv.conf

Now, type dig command along with your domain name to test the DNS server.

root@ubuntu20:~# dig www.osradar.local

; <<>> DiG 9.16.1-Ubuntu <<>> www.osradar.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65241
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: fabd20125b9ccbff010000005f8c7204e1387a993d58c22f (good)
;; QUESTION SECTION:
;www.osradar.local. IN A

;; ANSWER SECTION:
www.osradar.local. 604800 IN A 172.16.10.3

;; Query time: 4 msec
;; SERVER: 172.16.10.10#53(172.16.10.10)
;; WHEN: Sat Nov 28 16:49:08 UTC 2020
;; MSG SIZE rcvd: 100

And to test the reverse DNS, type

root@ubuntu:~# dig -x 172.16.10.3

; <<>> DiG 9.16.1-Ubuntu <<>> -x 172.16.10.3
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62529
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 7b8c9b8971f74afc010000005f8c72a8bdc5ebbdb4869578 (good)
;; QUESTION SECTION:
;3.10.16.172.in-addr.arpa. IN PTR

;; ANSWER SECTION:
3.10.16.172.in-addr.arpa. 604800 IN PTR www.osradar.local.

;; Query time: 0 msec
;; SERVER: 172.16.10.10#53(172.16.10.10)
;; WHEN: Sat Nov 28 16:51:52 UTC 2020
;; MSG SIZE rcvd: 122

So, you can see that both forward & reverse DNS are working properly. Hence, this is how you can install & Configure BIND DNS Server On Ubuntu 20.04

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article