06.12.2024

How to Configure BIND9 DNS Server on Ubuntu 20.04

In this tutorial, we will walk through the installation and basic configuration of the BIND9 DNS server.

How to configure BIND9 DNS Server on Ubuntu 20.04:

Install BIND9

The first thing you need to do is to update the package list and to install BIND9.

sudo apt update
sudo apt install bind9

After the installation process is complete, you can check if BIND9 is working.

nslookup google.com 127.0.0.1

The answer will be something like this:

Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: google.com
Address: 64.233.164.138
...

BIND9 configuration

The DNS server works right after installation. You need to configure it according to your usage purposes. First, allow BIND9 to work through the firewall.

sudo ufw allow Bind9

The main configuration file is named.conf.options, let's open it.

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

Some of the available options are listed below. Add the necessary to the "options" directive.

The "listen-on" directive allows you to specify the networks that the DNS server will serve. Don't write this or write "any;" to work for all addresses.

listen-on {
10.10.10.0/24;
10.1.0.0/16;
...
};

BIND9 only allows local queries by default. Add the necessary IP addresses to the "allow-query" directive or "any;" to allow all requests.

allow-query { any; };

Forwarders contain the IP addresses of DNS servers to which the request is redirected if our server does not contain the required data.

forwarders {
8.8.8.8;
8.8.4.4;
};

Save and close the file. Check the configuration:

sudo named-checkconf

If no errors appear, then everything is in order. Restart the service for the changes to take effect.

sudo systemctl restart bind9

BIND9 test

To check if the DNS server is working properly, enter the following command on any other remote computer. Replace dns-server-ip-address with the IP address of the DNS server.

nslookup ubuntu.com dns-server-ip-address

Output:

Server: dns-server-ip-address
Address: dns-server-ip-address#53
Non-authoritative answer:
Name: ubuntu.com
Address: 91.189.88.181
...

Now you have a working caching name server BIND9.

Next steps: