How to install & set up bind in ubuntu on local server or local system | Setup DNS in ubuntu | latest bind9 configuration.

We are going to set-up Bind in Ubuntu , with these below steps , follow each steps , than you will set-up successfully BIND on your local machine Ubuntu.

1- Set-up a Static IP Address & new Host name

Open your terminal on Ubuntu , to open the terminal press “ctrl+alt+t” .

Now , give command –

hostnamectl

This will show you ,your hostname like –

Now change your Host Name with the command –

hostnamectl set-hostname server.example.com

Your host name is now changed to – server.example.com

Now give the command –

ifconfig

You will see your machine IP address & network interface card name like –

In this case , as you could see in above figure, Network Interface card name is – enp4s0 , Our IP address is – 172.25.1.22.

Your Network Interface card may be different, so recognize your Network Interface Card name ,for further steps.

Now We have to set up a Static IP address , to set-up a static IP address , we have to open interface file , to open interface file , give command –

sudo vim /etc/network/interfaces

Now , a file will open , in this file you have to write –

 auto lo
 iface lo inet loopback
 auto enp4s0
 iface enp4s0 inet static
 address 172.25.1.22
 netmask 255.255.255.0
 dns-search example.com
 dns-nameserver 172.25.1.22

Here , above in 3rd & 4th line , you have to give your ,Interface Card name in place of “enp4s0”.

In 5th line above after “address” , give the new static , IP address.

Now press “esc” key than press “wq” , to modify the changes in file and exit from file.

Now give below command to restart network –

sudo systemctl restart networking

Now we have static IP address & host name , We are ready to set-up BIND , If some error come , restart your system, try to solve it , it will be ok.

2- Installing BIND 9

Now , to install BIND9 , give command-

sudo apt-get update
sudo apt-get install bind9 bind9utils

Now Bind9 is successfully installed.

3 – Stating Zones in “named.conf.local”

The main configuration file for bind configuration is “named.conf” , here it is mentioned , to configure zones , We have to configure it in “named.conf.local”.

Now to open “named.conf.local” , give command –

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

Now add below lines in this file to state forward and reverse zones –

zone "example.com" IN{
         type master;
         file "/etc/bind/forward.example.com";
 };
 zone "1.25.172.in-addr.arpa" IN{
         type master;
         file "/etc/bind/reverse.example.com";
 };

While creating reverse zone above , you have to eneter your IP address from last without last bit , like in our case , our IP address is “172.25.1.12” , so without last bit and by reversing we have “1.25.172”, which we have mentioned in reverse zone above.

Now we have to configure forward.example.com & reverse.example.com file .

4 – Configuring Forward and Reverse Zone

To configure forward zone and reverse zone, we have to create & configure“forward.example.com” file and “reverse.example.com” file which we have stated, above in “named.conf.local” file.

To create “forward.example.com” file , so that we could configure it give command –

cd /etc/bind
sudo cp db.local forward.example.com 

Above , we have copied “db.local” file because we need some similar configuration of “db.local” file in “forward.example.com” file.

Now to open “forward.example.com” file ,give command –

sudo vim forward.example.com

Now edit this file like below –

 ;
 ; BIND data file for local loopback interface
 ;
 $TTL    604800
 @       IN      SOA     server.example.com. root.server.example.com. (
                               2         ; Serial
                          604800         ; Refresh
                           86400         ; Retry
                         2419200         ; Expire
                          604800 )       ; Negative Cache TTL
 ;
 @       IN      NS      server.example.com.
 @       IN      A       172.25.1.22
 server  IN      A       172.25.1.22
 host    IN      A       172.25.1.22

Above We have configured forward zone , in which We have created five record as you could see above.

Firstly we have created “SOA”(Start of Authority Record) , than NS(Name Server) , than three “A”(IP Address) record, Now we have to create & configure “reverse.example.com” file for reverse zone.

To create “reverse.example.com” file , so that we could configure it give command –

cd /etc/bind
sudo cp db.local reverse.example.com 

Above , we have copied “db.local” file because we need some similar configuration of “db.local” file in “reverse.example.com” file.

Now to open “reverse.example.com” file ,give command –

sudo vim reverse.example.com

Now edit this file like below –

;
 ; BIND data file for local loopback interface
 ;
 $TTL    604800
 @       IN      SOA     server.example.com. root.server.example.com. (
                               2         ; Serial
                          604800         ; Refresh
                           86400         ; Retry
                         2419200         ; Expire
                          604800 )       ; Negative Cache TTL
 ;
 @       IN      NS      server.example.com.
 @       IN      PTR     example.com.
 server  IN      A       172.25.1.22
 host    IN      A       172.25.1.22
 22      IN      PTR     server.example.com.

In last line you have to mention, your last bit of IP Address, Here our IP Address is “172.25.1.22” , so we have mentioned 22 , you have to mention yours.

5- Checking Wheather Configuration is Correct or Wrong

To check the configuration , give the command –

sudo named-checkconf -z /etc/bind/named.conf

If ,It will show like below , than your configuration is perfect –

Now to check , configuration of forward and reverse zone , give command –

sudo named-checkzone forward /etc/bind/forward.example.com
sudo named-checkzone reverse /etc/bind/reverse.example.com

If it shows like below , than your configuration is perfect –

If it is showing any error , than go to that file and try to solve it !

6- Changing Ownership of file –

To change the ownership of file for both user and group give command –

cd /etc/bind
sudo chown -R bind:bind /etc/bind

To change the permission give command –

sudo chmod -R 755 /etc/bind

7 – Starting Bind9

To start bind9 , give command –

sudo systemctl start bind9

Now, for checking the status of bind9 , give command –

sudo systemctl status bind9

If it is showing like below in which all zones are loaded and active , than it’s all good.

If it is showing some issue in loading than you can restart bind with command –

sudo systemctl restart bind9

Now check the status of firewall with command –

sudo ufw status

If it is active than give command –

sudo ufw allow bind9

If firewall is inactive than you don’t have to execute above command for allowing of bind9.

Now go to resolv.conf file to mention IP address & host name or domain name , for it give command –

sudo vim /etc/resolv.conf

You have to mention it like below –

nameserver 172.25.1.22
search example.com

than press “esc” than “wq+enter” , to modify and exit from file.

Now to restart the network give command –

sudo systemctl restart networking
sudo systemctl restart NetworkManager

8 – Using Bind

Now our bind9 is set up successfully on ubuntu local machine , to see the DNS information of our zones give the command –

nslookup - 172.25.1.22

Than to check IP address of our domain “example.com” , type it & press enter like –

nslookup - 172.25.1.22
example.com

As in reverse to check domain of IP address “172.25.1.22” , type it & press enter like –

Now to check soa(start of authority record) for any domain , wheather in our zone on local machine or out of it , you could “set type=soa” & enter the name of domain .

Here for “example.com” as mention on bind zone in local machine –

nslookup - 172.25.1.22
set type=soa
example.com

Here for “google.com” , which hasn’t mention in zone file, but it has searched it from outside –

Now , you can change set type , and fetch the result according to your requirement , to know various set type you can go on – https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/nslookup-set-type

Now, our BIND is configured successfully, hope so you all have configured it successfully !