How to Configure BIND9 as a Primary DNS Server on Ubuntu 20.04

You can use the DNS server in different ways. In this tutorial, we will configure BIND9 as the primary DNS server for a domain name. After that, you can specify the IP addresses of various domain services, for example, the mail server, as well as third-level domains.
Before you start, perform the installation and basic configuration of BIND9.

DNS zone creating

In this tutorial, we will use «domain-name.com» as an example. Symply change it to your domain name. Also, you need to use your real IP addresses instead of 10.1.1.xxx in the example.

Let’s add zone information to the configuration.

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

Add these lines to it.

zone "domain-name.com" {
        type master;
        file "/etc/bind/db.domain-name.com";
        allow-transfer {; };
        also-notify {; };

Restart the service.

systemctl reload bind9

Zone file configuration

Create a zone file from the template and open it.

sudo cp /etc/bind/db.local /etc/bind/db.domain-name.com
sudo nano /etc/bind/db.domain-name.com

Replace localhost in the SOA record with the FQDN of your server with the «.» character at the end. In the example, this is «ns.domain-name.com.». Replace «root.localhost» with your valid admin email address with «.» instead of «@» in it and «.» at the end.
Serial — serial number of the change. You have to manually increment it every time you change the zone file. The secondary server monitors changes in the zone using this parameter.

$TTL    604800
@       IN      SOA     ns.domain-name.com. admin.domain-name.com. (
                              2        ; Serial
                         604800        ; Refresh
                          86400        ; Retry
                        2419200        ; Expire
                         604800 )      ; Negative Cache TTL
@       IN      NS      ns.domain-name.com.
@       IN      A
ns      IN      A
ns2     IN      A
mx      IN      A

The bottom of the file contains DNS records. The format of the record: hostname<tab>class<tab>DNS record type<tab>value. Where:

  • hostname — most often this value is a third-level domain name, and “domain-name.com” is filled in automatically. @ or none means an entry for the zone name (in this case, domain-name.com). You can also specify the FQDN with a dot at the end (for example, ns.domain-name.com.);
  • class is IN (Internet), indicates the type of network;
  • The most common types of DNS records: A, NS, MX, CNAME, TXT. «A» contains the IP address of the domain name, «NS» is the IP address of the zone’s DNS server, «MX» — the mail server, «CNAME» — alias referring to the value of the specified record, «TXT» — custom entry;
  • value — IP address, host name, text information.

Restart the rndc.

sudo rndc reload

You can check the DNS server. Enter this command from any remote computer.

nslookup domain-name.com

Replace domain-name.com with your FQDN and with the address of the newly configured name server. Your domain’s DNS A-record will be used as the response. In the given example, this is

Next stepBIND9 as a Secondary DNS Server.