How to Install and Configure a Simple DNS (BIND) Server on Debian 9

In the following tutorial, we’re going to go through the process of installing and configuring a simple DNS (BIND) server on your Debian 9 VPS. This will allow you to host/manage the DNS records for your domain/s.

Before we proceed with the setup process, let’s first talk about what the Domain Name System (DNS) is, as well as what a DNS server is.Installing and Configuring a Simple DNS BIND Server in Debian 9

The Domain Name System (DNS) is technology that resolves the domain names/hostnames to IP addresses so that we can easily access the services using domain names instead of using IP addresses. For example, if you wanted to visit a website through its IP address, you’d have to enter a specific IP in the web browser’s address bar. But with the DNS, you can simply type “your_domain.com” to get there much more quickly. It’s easier to remember, and it’s more user-friendly. That’s why people consider the DNS as “the phonebook of the Internet”. Nobody wants to remember an IP, but everyone can and does remember a domain name. A Domain Name System uses DNS servers for its functionality, so a DNS server is any authoritative DNS host registered to join the Domain Name System (DNS).

Prerequisites

  • A Server running Debian 9
  • SSH access with root privileges, or access to the root user itself
  • Domain name
  • Registered name servers

Before we begin, in this tutorial we are going to use the domains ns1.your_domain.net and ns2.your_domain.net as example domains. To follow this tutorial, you’ll need to go to your domain registrar (the company that you bought your domain from) and register a domain name like your_domain.net. Remember to follow along with the name change throughout the rest of this guide. Also make sure you point them to your server IP address – in this tutorial we will be using 12.34.56.78 for explanatory purposes.

Step 1: Log in via SSH and Update Your System

Log in to your Debian 9 VPS with SSH as the root user, or as a user with sudo privileges:

ssh [email protected]_Address -p Port_Number

Remember to replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port.

You can check whether you have the proper Debian 9 version installed on your server with the following command:

# lsb_release -a

You should get this output (or something similar to this):

Distributor ID: Debian
Description: Debian GNU/Linux 9.7 (stretch)
Release: 9.7
Codename: stretch

Then, run the following command to make sure that all installed packages on the server are updated to the latest available version:

# apt update && apt upgrade

Step 2: Install and Configure the Name Server

In this tutorial, we will install bind9 and dnsutils.

# apt install bind9 dnsutils -y

Once the installation is complete, edit the /etc/bind/named.conf.local configuration file and add something like this: (make sure you change your_domain.net and 12.34.56.78 to your actual domain name and IP address)

# nano /etc/bind/named.conf.local
zone "your_domain.net" {
type master;
file "/etc/bind/zones/your_domain.net.db";
};

The next thing we’re going to do is to create a zone file for the your_domain.net domain. Do it by entering the following command:

# mkdir -p /etc/bind/zones && nano /etc/bind/zones/your_domain.net.db
; Zone file for your_domain.net @ 14400 IN SOA ns1.your_domain.net. root.your_domain.net. ( 2012110501 ; serial, todays date+todays 28800 ; refresh, seconds 7200 ; retry, seconds 3600000 ; expire, seconds 86400 ) ; minimum, seconds your_domain.net. 14400 IN NS ns1.your_domain.net. your_domain.net. 14400 IN NS ns2.your_domain.net. ns1 14400 IN A 12.34.56.78 ns2 14400 IN A 12.34.56.78 mail 14400 IN CNAME your_domain.net. www 14400 IN CNAME your_domain.net. ftp 14400 IN CNAME your_domain.net. your_domain.net. 14400 IN A 12.34.56.78 your_domain.net. 14400 IN MX 0 your_domain.net.

With all of these configuration files in place, we should now have a working DNS server. The last thing you need to is to restart your DNS server and add it to your system startup services using:

# systemctl restart bind9
# systemctl enable bind9

Now, you can go to your domain registrar again, change the existing authoritative name servers to ns1.your_domain.net and ns2.your_domain.net. You can verify the changes and the DNS propagation at https://www.whatsmydns.net/#NS/your_domain.net.

If you want to use the name servers for your anotherdomain.com, you can simply copy /etc/bind/zones/your_domain.net.db and make several changes.

# cp /etc/bind/zones/your_domain.net.db /etc/bind/zones/anotherdomain.com.db
# nano /etc/bind/zones/anotherdomain.com.db
; Zone file for anotherdomain.com
@ 14400 IN SOA ns1.your_domain.net. root.your_domain.net. ( 2012110501 ; serial, todays date+todays 28800 ; refresh, seconds 7200 ; retry, seconds 3600000 ; expire, seconds 86400 ) ; minimum, seconds anotherdomain.com. 14400 IN NS ns1.your_domain.net. anotherdomain.com. 14400 IN NS ns2.your_domain.net. mail 14400 IN CNAME anotherdomain.com. www 14400 IN CNAME anotherdomain.com. ftp 14400 IN CNAME anotherdomain.com. anotherdomain.com. 14400 IN A 12.34.56.78 anotherdomain.com. 14400 IN MX 0 anotherdomain.com.

Save the changes and exit from nano.

The DNS records for anotherdomain.com have been added, now it is time to include the anotherdomain.com in named.conf.local file.

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

Edit your existing configuration and make it like the following.

zone "your_domain.net" {
type master;
file "/etc/bind/zones/your_domain.net.db";
};

zone "anotherdomain.com" {
type master;
file "/etc/bind/zones/anotherdomain.com.db";

};

Save the changes and exit.

Then, we need to restart BIND9 after every change we make, like adding a new domain or after editing the DNS records.

# systemctl restart bind9

Congratulations! At this point BIND9 has been successfully installed on your VPS, and you can use your name servers for all your domains.


Install and Configure a Simple DNS BIND Server on Debian 9Of course, you don’t have to know how to install and configure a DNS server using BIND9 on Debian 9 if you use our Managed Debian 9 VPS Hosting service. You can simply ask our support team to configure your DNS server on Debian 9 for you. They are available 24/7, and will be able to help you with the installation of BIND9 on Debian 9.

PS. If you enjoy reading this blog post on how to configure your DNS server using BIND on Debian 9, feel free to share it on social networks using the shortcuts below, or simply leave a comment. Thank you.