How to Setup Bind (DNS Server) on Ubuntu 24.04 | 22.04

Hello techies, in this blog post, we will cover how to setup Bind (DNS Server) on Ubuntu 24.04 and 22.04 LTS (Jammy Jellyfish) step by step.

BIND or BIND 9 is an open source implementation of DNS, available for almost all Linux distributions. BIND stands Berkeley Internet Name Domain & it allows us to publish DNS information on internet as well as allows us to resolve DNS queries for the users. BIND is by far the most used DNS software on Internet.

DNS or Domain Name System, as we know is an internet service that is used to translate the user friendly domain into computer friendly IP addresses. Not only can we translate domain names to IP addresses, we can also perform reverse translation i.e. from IP addresses to domain name translations. In this post, we are going to learn to setup a private DNS server by implementing BIND 9 on Ubuntu 24.04  and Ubuntu 22.04. Steps are identical for these two Ubuntu versions.

Prerequisites

  • Minimal Installed Ubuntu 24.04 | 22.04
  • Sudo User with admin privileges
  • Internet connectivity

Lab Setup

  • Bind Server IP (Ubuntu 22.04)  = 192.168.0.40
  • Domain Name = linuxtechi.local
  • Private Network = 192.168.0.0/24

Without any further delay, let’s begin with bind 9 installations,

1) Install Bind 9 Package

We need to install ‘bind9 bind9utils bind9-doc dnsutils’ to install BIND 9 & related tools. Open your terminal & execute the following apt command,

$ sudo apt update
$ sudo apt install -y bind9 bind9utils bind9-doc dnsutils

2) Setup Bind (DNS Server) on Ubuntu 24.04 | 22.04

Once all the packages have been installed, we will move into the configuration part. All configuration files for BIND are located in folder ‘/etc/bind’.

One of the important configuration file for bind is “/etc/bind/named.conf.options“, from this file we can set the followings parameters:

  • Allow Query to your dns from your private network (As the name suggests only the systems from your private network can query dns sever for name to ip translation and vice-versa)
  • Allow recursive query
  • Specify the DNS port ( 53)
  • Forwarders (DNS query will be forwarded to the forwarders when your local DNS server is unable to resolve query)

As per my private network settings, I have specified the following parameters:

$ sudo vi /etc/bind/named.conf.options

acl internal-network {
192.168.0.0/24;
};
options {
        directory "/var/cache/bind";
        allow-query { localhost; internal-network; };
        allow-transfer { localhost; };
        forwarders { 8.8.8.8; };
        recursion yes;
        dnssec-validation auto;
        listen-on-v6 { any; };
};

Bind-Named-Conf-Ubuntu-Linux

Next Important Configuration file is “/etc/bind/named.conf.local“, in this file we will define the zone files for our domain, edit the file add the following entries:

$ cd /etc/bind
$ sudo vi named.conf.local
zone "linuxtechi.local" IN {
        type master;
        file "/etc/bind/forward.linuxtechi.local";
        allow-update { none; };
};
zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "/etc/bind/reverse.linuxtechi.local";
        allow-update { none; };
};

Save the file & exit. Here we have mentioned locations for our forward lookup zone file & reverse lookup zone files. Next we will create the mentioned forward & reverse zone files.

Firstly create the forward lookup zone file, Sample zone files (db.local) are already there in ‘/etc/bind’ folder, we can use and copy sample zone file,

$ cd /etc/bind
$ sudo cp db.local forward.linuxtechi.local
$ sudo vi forward.linuxtechi.local
$TTL 604800
@ IN SOA primary.linuxtechi.local. root.primary.linuxtechi.local. (
                                   2022072651 ; Serial
                                   3600 ; Refresh
                                   1800 ; Retry
                                   604800 ; Expire
                                   604600 ) ; Negative Cache TTL
;Name Server Information
@       IN  NS    primary.linuxtechi.local.

;IP address of Your Domain Name Server(DNS)
primary IN  A     192.168.0.40

;Mail Server MX (Mail exchanger) Record
linuxtechi.local. IN MX 10   mail.linuxtechi.local.

;A Record for Host names
www     IN  A    192.168.0.50
mail    IN  A    192.168.0.60

;CNAME Record
ftp     IN CNAME www.linuxtechi.local.

Your forward lookup file should look like something below:

Forward-lookup-zone-file-ubuntu

Here, we have added information regarding our DNS server & have also added A records for couple of servers, also added record for a mail server & CNAME record for ftp server. Make sure you edit this file to suit your network.

Next we will create a reverse lookup zone file at the same location,sample reverse lookup zone file is present at ‘/etc/bind‘ folder.

$ sudo cp db.127 reverse.linuxtechi.local
$ sudo vi /etc/bind/reverse.linuxtechi.local
$TTL 86400
@ IN SOA linuxtechi.local. root.linuxtechi.local. (
                           2022072752 ;Serial
                           3600 ;Refresh
                           1800 ;Retry
                           604800 ;Expire
                           86400 ;Minimum TTL
)
;Your Name Server Info
@ IN NS primary.linuxtechi.local.
primary   IN  A    192.168.0.40
;Reverse Lookup for Your DNS Server
40        IN PTR   primary.linuxtechi.local.
;PTR Record IP address to HostName
50        IN PTR   www.linuxtechi.local.
60        IN PTR   mail.linuxtechi.local.

Your Reverse Zone Lookup file should look like below:

Reverse-Lookup-zone-file-ubuntu-linux

Save file & exit.

Update the following parameter in ‘/etc/default/named ‘ file, so that dns service starts listening on IPv4

OPTIONS="-u bind -4"

Now all we have to do is to start and enable the BIND service to implement the changes made,

$ sudo systemctl start named
$ sudo systemctl enable named

View the bind service status, run

$ sudo systemctl status named

Check-Named-Service-Status-Ubuntu

Note : In case OS firewall is running on your bind server then execute the below command to allow 53 port

$ sudo ufw allow 53
Rule added
Rule added (v6)
$

3) Validating Syntax of Bind Configuration and Zone files

If you want to cross verify the syntax of your bind 9 configuration file (named.conf.local). Use the command “named-checkconf“, example is shown below:

$ sudo named-checkconf /etc/bind/named.conf.local

If there is no syntax error in your bind configuration file, then it should return to shell without showing any errors.

To cross verify the syntax your forward and reverse lookup zone files , use the command “named-checkzone”, example is shown below:

$ sudo named-checkzone linuxtechi.local /etc/bind/forward.linuxtechi.local
zone linuxtechi.local/IN: loaded serial 2022072651
OK
$
$ sudo named-checkzone linuxtechi.local /etc/bind/reverse.linuxtechi.local
zone linuxtechi.local/IN: loaded serial 2022072752
OK
$

4) Test DNS Server with dig & nslookup

To test out our BIND 9 DNS server, we will use another Ubuntu machine & will change its DNS to point out our DNS server. To change the DNS server, open ‘/etc/resol.conf’ & make the following DNS entry,

$ sudo vi /etc/resolv.conf
search linuxtechi.local
nameserver 192.168.0.40

save the file & exit. We now have our client ready with DNS pointing to our server. We will now use a CLI tool called ‘dig‘ command , which is used to get find out DNS & its related information. Execute the following command from terminal,

$ dig primary.linuxtechi.local

we should get the following output of above,

dig-command-query-ubuntu

This output shows that our DNS is working fine.

Let’s do reverse lookup query(PTR):

$ dig -x 192.168.0.40

Output of command should be something like below:

dig-ptr-query-ubuntu

Also we can run ‘nslookup‘ command against our DNS server to confirm the output of dig command,

$ nslookup primary.linuxtechi.local

& it should produce the following output,

nslookup-command-ubuntu

Note:  While running dig command, if you get ‘command not found’ error than we need to install ‘dnsutils‘ package as dig command is part of ‘dnsutils’ package,

$ sudo apt install dnsutils -y

Now that our server is working fine, we can add other servers like mail server, ftp server or web servers to DNS server configuration files by creating the appropriate records as per requirement. Also we have only setup a local DNS server in this tutorial, if you need to setup a public DNS than you will require a Public IP address for the same.

With this we end our post on how to install & configure DNS server on Ubuntu 22.04 using BIND 9. Please do send your valuable feedback/queries to us, we will be happy to address them all.

Read AlsoHo to Install and Configure Webmin on Debian / Ubuntu

15 thoughts on “How to Setup Bind (DNS Server) on Ubuntu 24.04 | 22.04”

  1. Hi, thank you very much for the tutorial. Can someone please explain why it was a requirement to put “primary” before the “.domainname.”.

    Thank you in advanced,

  2. Hi!
    I have a question. If I registered a domain on freenom.com that I want to configure local dns server with registered domains. Have to I write public or private ip on name.conf.local file? I copied db.local db.something. Which ip write in db.something in A record?

Leave a Comment

Your email address will not be published. Required fields are marked *