Configure a Private DNS on Debian
Tags: linux, debian, dns
Published: 2023-11-22 17:57:29

note : i am doing this on Debian 10 (buster) and running it on virtual machine and i am using the root or am the root user . so use `sudo` befour every command


## **Get important tools**

**Step 1:**

First of all we need some important tools for configure a private DNS so Install Bind9 and tools

```
 sudo apt install bind9 bind9utils bind9-doc -y
```

##**Configure DNS**


**Step 2:**

After installing Bind we can proceed to our main objective to configure a DNS

First open the name.conf.options

 

```
 nano /etc/bind/named.conf.options
```



After opening the file Edit the file to add a acl ( access control list) and in it write your server ip address and clint ip address

```
acl “trusted” {
	192.168.18.1; 
	192.168.18.11;
 };
```
In this acl section first ip `192.168.18.1` is our server ip and `192.168.18.11` is our client

After that in the option section write the following 
```
recursion yes;
Allow-recursion {trusted;};
listen-on {192.168.18.1};
allow-transfer {none;};
forwarders {
	8.8.8.8;
	8.8.4.4;
};

```


![named.conf.options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wgd3g0cefcngvoaefit.png)

**Step 3 :**

Now open named.conf.local for defining zones. 


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

In this file we define our forward and backward zones

In forward zone we write out domain name in the name section and we provide and path to the forward zone file

And in backward zone we do similar things but in the name section we write our revers ip , in my case it is  `“18.168.192”`



![zones](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chlfh7lliurtjq79cfxz.png)


**Step 4 :**

Now we need to create a folder for our zones 

```
 mkdir /etc/bind/zones
```







**Step 4.1**
	Copy db.local for making forward zone and name after your domain name 

	

```
sudo cp /etc/bind/db.local /etc/bind/zones/db.hello.com
```







**Step 4.2**

Copy db.127 for creating reverse zone and name it 	

```
 sudo cp /etc/bind/db.127 /etc/bind/zones/db.192.168.18
```






**Step 5**
	 Open forward zone file 

```
 nano /etc/bind/zones/db.hello.com
```

After opening the forward zone do the following

First, you will want to edit the SOA record. Replace the first “localhost” with ns’s FQDN, then replace “root.localhost” with `“admin.hello.com”`. Every time you edit a zone file, you need to increment the serial value before you restart the named process. We will increment it to `“3”`. 

![forward zone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdyvbcqyrbnx6yuicdxh.png)

Next, delete the three records at the end of the file (after the SOA record).

 	
![delete soa](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/an5iw6bvwninvwaw4v12.png)

Now, add the A records for your server & hosts that belong in this zone. This includes any server whose name we want to end with `“.hello.com.”` (substitute the names and private IP addresses).

Befour that add NS Record for you server

![nsRecord](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwibyxlkomlfyywrgjca.png)

Save and close the db.hello.com file.
Final result


![db.hello](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyl1eltxywzcke9y0ay3.png)

**Step 6:**

Now open reverse zone file 

Reverse zone files are where we define DNS PTR records for reverse DNS lookups. Each reverse zone specified in the named.conf.local file, create a reverse zone file. We will base our reverse zone file(s) on the sample db.127 zone file. Copy it to the proper location with the following commands (substituting the destination filename so it matches your reverse zone definition): 


	

```
nano /etc/bind/zones/db.192.168.18
```

 In the same manner as the forward zone file, you will want to edit the SOA record and increment the serial value.


![reverse soa](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg9cu7iadlvz8hoknvza.png)

 Now delete the two records at the end of the file (after the SOA record). If you’re not sure which lines to delete, they are marked with a “delete this line” comment below.

![deletw line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d32qs7a9t3dpbvi57uga.png)
 At the end of the file, add your name server records with the following lines (replace the names with your own). 

![ptr record](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sawmp1z1bw17wxkjorj.png)
 Note that the first column consists of the last two octets of your servers’ private IP addresses in reversed order.

![db.192.168.18](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vh7v4ayz7pwo6m3mjbzb.png)



**Step 7:**

Remember to check your conf and zone for errors file by following command 

Named-checkconf
Named-checkzone

Google it to know how to use

Or let me be generous 

Run the following command to check the syntax of the named.conf* files:

 

> named-checkconf	
			
eg,:
```
named-checkconf /etc/bind/named.conf.options
```
					

To check the “hello.com” forward zone configuration, run the following command:

```
named-checkzone hello.com /etc/bind/zones/db.hello com	
```
				
	
And to check the “18.168.192.in-addr.arpa” reverse zone configuration, run the following command:

```
sudo named-checkzone 18.168.192.in-addr.arpa /etc/bind/zones/db.192.168.18	
```



**Step 8:**

Restart the Bind by this command

```
 systemctl restart bind9
```


**Step 9:**

Open network interface file for adding dns name and ip

	

```
 nano /etc/network/interfaces
```

	

![dns search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxu86bs8cge9bx6uonzd.png)

Add the following and remember to change the address to you ones



**Step 10:**

Install resolvconf

```
sudo apt install resolvconf
```

**Step 10.1**

Restart your networking services, applying the new changes with the following commands

```
ifdown --force eth1 && sudo ip addr flush dev eth1 && sudo ifup --force eth1

```


**Step 10.2**

```
 cat /etc/resolv.conf

```
To check the settings for dns

**Step 11**

Final step to check if domain name or dns is working 
Open your bowser and your url
In my case which is 

`http://hello.com`

##Thank You :heart:

thank you for reading this far if there is any problem or any suggestion or anything just contact me

##Reference 
How To Configure BIND as a Private Network DNS Server on Debian 9

{% embed https://www.digitalocean.com/community/tutorials/how-to-configure-bind-as-a-private-network-dns-server-on-debian-9 %}