Serverspace is Launching a New Flexible Plan for Everyone

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

Joe Harris
September 19, 2020

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 «» as an example. Symply change it to your domain name. Also, you need to use your real IP addresses instead of in the example.

Let’s add zone information to the configuration.

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

Add these lines to it.

zone "" {
        type master;
        file "/etc/bind/";
        allow-transfer {; };
        also-notify {; };
  • type may be master, slave, forward, hint;
  • file — indicates the path to the new zone file;
  • allow-transfer — list of DNS servers that are allowed to transfer the zone;
  • also-notify — the primary DNS server will notify these servers of zone changes.

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/
sudo nano /etc/bind/

Replace localhost in the SOA record with the FQDN of your server with the «.» character at the end. In the example, this is «». 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 (
                              2        ; Serial
                         604800        ; Refresh
                          86400        ; Retry
                        2419200        ; Expire
                         604800 )      ; Negative Cache TTL
@       IN      NS
@       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 “” is filled in automatically. @ or none means an entry for the zone name (in this case, You can also specify the FQDN with a dot at the end (for example,;
  • 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.


Replace 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.

Start Your Cloud Journey Migration made simplified. Take the first step right now.
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.