# Installing DNS Server on Ubuntu 22.04 with BIND

Domain Name System (DNS) is a critical service for the internet that translates human-friendly domain names (like [`www.example.com`](http://www.example.com)) into IP addresses (like `192.168.1.1`) that computers use to communicate. In this guide, we’ll walk through setting up a DNS server on a Linux system using **BIND** (Berkeley Internet Name Domain), one of the most widely used DNS server software.

**<mark>Step 1: Update System Packages</mark>**

```plaintext
sudo apt update
```

**<mark>Step 2: Install BIND</mark>**

First, we need to install the BIND software package. This can be done using the default package manager of your Linux distribution.

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726893301185/a39ee94c-44ea-4ef0-a693-35cb885925e2.png align="center")

Once installed, the BIND service will automatically start. You can check the status by running:

```plaintext
sudo systemctl status bind9
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726894506715/0a4b3012-1dd2-4cb5-af87-6e1b35e192b5.png align="center")

**<mark>Step 3: Configure BIND9</mark>**

Now, let’s configure BIND9 to act as a DNS server for your domain. We’ll be configuring it as a master DNS server for the domain [`example.com`](http://example.com).

#### 3.1. Define DNS Zone

Zones are used to define the DNS records for a particular domain. Start by editing the configuration file:

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

Add the following lines to define the zone for [`example.com`](http://example.com):

```plaintext
// Forward Zone Definition
zone "example.com" {
    type master;
    file "/etc/bind/db.example.com";
};
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726898246375/9d59dadc-c323-439c-a737-905f925487d8.png align="center")

#### 3.2. Create Forward Zone File

Next, create the forward zone file where DNS records for your domain will be stored:

```plaintext
sudo cp /etc/bind/db.local /etc/bind/db.example.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726898507519/4d0e82eb-a157-4e13-80e9-f4d2c198f628.png align="center")

Open the zone file for editing:

```plaintext
sudo nano /etc/bind/db.example.com
sudo nano /etc/bind/db.dineshcloud.com
```

Replace the placeholder values with your own. Here’s an example:

```plaintext
;
; BIND data file for dineshcloud.com
;
$TTL    604800
@       IN      SOA     ns1.dineshcloud.com. root.dineshcloud.com. (
                        2023092001      ; Serial in YYYYMMDDXX format
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.dineshcloud.com.
ns1     IN      A       192.168.13.162     ; Replace with your DNS server's IP address
www     IN      A       192.168.13.162     ; Replace with the web server's IP address
@       IN      A       192.168.13.162     ; Replace with your DNS server's IP address
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726898679206/3efc84d6-8585-47ee-8510-fac2d80814fe.png align="center")

#### 3.3. Reverse Zone Configuration (Optional)

To enable reverse DNS lookup (mapping IP addresses to domain names), add a reverse zone to the `named.conf.local` file:

```plaintext
// Reverse Zone Definition
zone "1.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/db.192.168.1";
};
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726898794627/7e14d960-a62a-4114-8297-14377d567213.png align="center")

Now, create the reverse zone file:

```plaintext
sudo cp /etc/bind/db.127 /etc/bind/db.192.168.1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726896853434/1ca79c1c-b4e6-498f-b38a-971fd198e0e6.png align="center")

Open the zone file for editing:

```plaintext
sudo nano /etc/bind/db.192.168.1
```

Edit the file as shown below:

```plaintext
;
; BIND reverse data file for 192.168.13.x network
;
$TTL    604800
@       IN      SOA     ns1.dineshcloud.com. root.dineshcloud.com. (
                        2023092001      ; Serial in YYYYMMDDXX format
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.dineshcloud.com.
162     IN      PTR     ns1.dineshcloud.com.    ; PTR record for 192.168.13.162
```

In this configuration, `10 IN PTR` [`example.com`](http://example.com)`.` maps the IP address `192.168.1.10` back to [`example.com`](http://example.com).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726898964275/92ac347f-fcb7-41c7-a583-593ef09eb486.png align="center")

**<mark>Step 4: Check Configuration</mark>**

To verify that your configuration files are correct, run the following command:

```plaintext
sudo named-checkconf
sudo named-checkzone example.com /etc/bind/db.example.com
sudo named-checkzone 1.168.192.in-addr.arpa /etc/bind/db.192.168.1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726899077194/f58b9010-2617-44a8-a910-9e65efa485cd.png align="center")

If there are no errors, you can restart BIND9:

```plaintext
sudo systemctl restart bind9
```

**<mark>Step 5: Configure DNS Clients</mark>**

For your Ubuntu server to resolve domain names using your DNS server, update the `/etc/resolv.conf` file with your DNS server’s IP:

```plaintext
sudo nano /etc/resolv.conf
```

Add the following line:

```plaintext
nameserver 192.168.13.162
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726897835264/7a69d59f-2a14-4c7b-bd6b-e8c498ac2239.png align="center")

After making any changes, restart or reload the BIND service to apply them:

```plaintext
sudo systemctl restart bind9
```

**<mark>Step 6: Test DNS Server</mark>**

To ensure your DNS server is functioning correctly, you can use the `dig` command:

```plaintext
dig example.com
```

This should return the A record for [`example.com`](http://example.com), as defined in your zone file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726899154643/ecfc127b-f883-44ec-be5d-dd6cfa5e2465.png align="center")

Use the `nslookup` command to query your DNS server directly

```plaintext
nslookup dineshcloud.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726899870670/cfc4d370-3392-40d2-8719-55327ae2afe2.png align="center")

```plaintext
ping dineshcloud.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726899806859/70fe53f2-0a0e-4d44-bea0-3d1d21b8085e.png align="center")

### Conclusion

Congratulations! You have successfully set up a DNS server on Ubuntu using BIND9. This basic configuration will allow you to manage DNS records for your domain and serve them to clients. For more advanced features like DNSSEC or caching, BIND9 offers extensive documentation to explore further.
