A DNS server is a computer that acts as a translator between the IP address and the domain name. It is responsible for translating the domain name into its corresponding IP address. By setting up a DNS server on Ubuntu, you will be able to manage your DNS records and improve the performance of your website.

Advertisement

Are you looking for an easy way to set up a DNS server on Ubuntu? Well, you have come to the right place! In this blog article, I will provide you with a comprehensive step-by-step guide on how to quickly and easily set up a DNS server on Ubuntu.

Whether you are a beginner or an expert, this guide will help you set up a DNS server on Ubuntu in no time. So, let’s get started!

Step 1: Install Packages

The very first thing you need to do when setting up a DNS server on Ubuntu is to install the DNS software. It’s a simple process. All you have to do is type a command into the computer, and it will install the software you need to get your DNS server running.

sudo apt update 
sudo apt install bind9 -y 

Step 2: Create Forward Zone File

A forward DNS zone is responsible for translating the domain name into the corresponding IP address. To set up a forward DNS zone, you need to create a zone file for each domain that you want the DNS server to manage. For example, if your domain is example.net, then create the zone files by running the following command:

sudo nano /etc/bind/example.net.zone

Add the following content


; Forward Zone file for example.net
$TTL 14400
@      86400    IN      SOA     ns1.example.net. webmaster.example.net. (
                3013040200      ; serial, todays date+todays
                86400           ; refresh, seconds
                7200            ; retry, seconds
                3600000         ; expire, seconds
                86400           ; minimum, seconds
      )
ns1             IN A 192.168.1.212
ns2             IN A 192.168.1.212
example.net.   86400  IN        NS      ns1.example.net.
example.net.   86400  IN        NS      ns2.example.net.
example.net.          IN        A       192.168.1.100
www                   IN        CNAME   example.net.

Save the file and close it.

Then use named-checkzone command to verify the syntax of the configuration file.

sudo named-checkzone example.net /etc/bind/example.net.zone 

On successful, an OK message will appear on the output screen.

Step 3: Create Reverse Zone File (Optional)

Generally, reverse DNS configuration is not required, but in some cases, you may need to configure it. This is used to resolve the domain name corresponding to an IP address. For example, we are using the 192.168.1.0/32 IP range in our intranet. Create reverse DNS file named /etc/bind/db.1.168.192 with following content.

sudo vi /etc/bind/db.1.168.192 

and add following content


; BIND reverse data file for local loopback interface
;
$TTL    604800
@ IN SOA ns1.example.net. root.ns1.example.net. (
                     3013040200         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.example.net.
100     IN      PTR     example.net.
101     IN      PTR     otherdomain.com.

Save the file and verify the file syntax:

named-checkzone 192.168.01.0/32 /etc/bind/db.1.168.192 

On successful, an OK message will appear on the output screen.

Step 4: Update Bind9 Main Configuration

The next step in setting up a DNS server on Ubuntu is to configure the DNS server. You can do this by editing the configuration file. You can find the configuration file by running the following command:

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

Append following content


zone "example.net" IN {
        type master;
        file "/etc/bind/example.net.zone";
};

zone "1.168.192.in-addr.arpa" {
        type master;
        file "/etc/bind/db.1.168.192";
};

Save the file and check the configuration files:

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

On successful, nothing will appear on the output screen.

Step 5: Restart bind9 Service

After verifying all configuration files, restart the bind9 service to apply changes with:

sudo systemctl restart bind9

then check its status using:

sudo systemctl status bind9
Output
● named.service - BIND Domain Name Server Loaded: loaded (/lib/systemd/system/named.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2024-01-04 12:17:31 IST; 2h 16min ago Docs: man:named(8) Process: 10725 ExecStart=/usr/sbin/named $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 10726 (named) Tasks: 4 (limit: 2271) Memory: 5.6M CPU: 146ms CGroup: /system.slice/named.service └─10726 /usr/sbin/named -u bind

The bind9 service should be active and running.

Step 6: Testing the DNS Server

Once you have configured the DNS server, you need to test it to make sure that it is working properly. You can do this by running the following command:

dig your_domain.com

This command will query the DNS server for information about the domain example.com. If the DNS server is configured correctly, you should be able to see the IP address of the domain in the output.

Verify Forward Zone:

dig example.net
Output
; > DiG 9.16.1-Ubuntu > example.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER

Verify Reverse Zone:

dig -x 192.168.1.100 
Output
; > DiG 9.16.1-Ubuntu > -x 192.168.1.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER

Conclusion

Setting up a DNS server on Ubuntu is a relatively straightforward process. In this blog article, I have provided you with a comprehensive step-by-step guide on how to quickly and easily setup a DNS server on Ubuntu, Debian and Linux Mint. I hope this guide was helpful and that you were able to set up a DNS server on Ubuntu without any issues.

If you have any questions or comments, please feel free to leave them in the comments section below. I would love to hear your feedback!

Share.

2 Comments

  1. How did you disable / remove dnsmasq so that port 53 was available for bind9 to use as a dns server?

    This is a problem on Linux Mint 17 which puts bind9 on port 953 when dnsmasq is already installed. (it is installed and active and attached to port 53 by default when you install Linux Mint 17 )

    I added bind9 to my system and am now experiencing 15 second or longer delays in responses to queries from remote hosts. This delay blows mail services out of the water and delays client access to the web server. My bind9 server is being used as an authoritative dns for my domain so this affects everything associated to the domain.

Leave A Reply

Exit mobile version