Learning Center
Linux

Setting Up a DNS Server

10 Apr 2025
Hostman Team
Hostman Team

A personal DNS server can be useful if your provider doesn't offer this service or if existing solutions don't suit your needs. The easiest way to set one up is via a control panel (cPanel, CloudPanel, HestiaCP, etc), but you can also do it manually using the terminal and the Linux DNS Server BIND 9.

Preparing the Server
Copy link

Let's say you've rented a Hostman Linux VPS and want to use your own DNS servers. To do that, you need to meet two conditions:

  1. Order another public IP address — DNS setup requires at least two IPs.
  2. Open DNS port 53, which is necessary for the nameserver to work.

Ubuntu/Debian

Update the package list:

apt update

Allow incoming packets on port 53 UDP in the firewall:

iptables -I INPUT -p udp --dport 53 -j ACCEPT

Save the firewall rules:

iptables-save

CentOS

Install system updates:

yum update

Install time synchronization utility:

yum install chrony

Set your timezone, for example:

timedatectl set-timezone Europe/Cyprus

Enable and start the time synchronization service:

systemctl enable chronyd --now

Open port 53:

firewall-cmd --permanent --add-port=53/udp

Apply the updated firewall rules:

firewall-cmd --reload

Installing the DNS Server
Copy link

This guide uses BIND 9 to create an IP-based DNS server.

Ubuntu/Debian

Install required packages:

apt-get install bind9 dnsutils

Enable autostart:

systemctl enable bind9

Start the service:

systemctl start bind9

Check if it's running:

systemctl status bind9

Look for active status in the output.

CentOS

Install the DNS utility:

yum install bind

Enable autostart:

systemctl enable named

Start the service:

systemctl start named

Check its status:

systemctl status named

You should see active in the output.

Basic DNS Server Configuration
Copy link

The settings are defined in the configuration file.

Ubuntu/Debian

Open the config file:

vi /etc/bind/named.conf.options

In the listen-on block, specify the networks, e.g.:

listen-on {
    10.10.10.0/24;
    10.1.0.0/16;
};

To allow the DNS server to listen on all interfaces, either omit this line or use any.

In the allow-query line, specify who can make queries:

allow-query { any; };

Restart the service for changes to take effect:

systemctl restart bind9

CentOS

Open the config file:

vi /etc/named.conf

Find these lines:

listen-on port 53 { 127.0.0.1; localhost; 192.172.160.14; };
...
allow-query     { any; };

In the listen-on line, after localhost, specify the DNS IP address. This is the IP on which the host will accept queries. Use any to listen on all addresses.

In the allow-query line, define query permissions. any allows queries from everyone. You can also restrict it to a specific subnet, e.g., 192.172.160.0/24.

Apply the config:

systemctl restart named

Global Options
Copy link

Besides the basics, you can fine-tune the server using other global parameters:

Argument

What It Configures

directory

Working directory (default is /var/named if not specified)

forwarders

IPs to forward unresolved queries to (e.g., Google's DNS)

forwarders { 
8.8.8.8; 
8.8.4.4; 
};

forward

Options: FIRST or ONLY. FIRST tries forwarders first, then internal. ONLY skips internal search.

listen-on

Interfaces that BIND listens on (usually port 53 UDP)

allow-transfer

Hosts allowed for zone transfers

allow-query

Who is allowed to send DNS queries

allow-notify

Hosts allowed to receive zone change notifications

allow-recursion

Hosts that can make recursive queries. Default is unrestricted.

Testing
Copy link

To check if the DNS server accepts queries from clients, use the nslookup utility.

From another computer:

nslookup site-example.com 192.172.160.14

This checks the IP address of site-example.com using DNS server 192.172.160.14.

Alternatively, use dig:

dig @192.172.160.14 site-example.com

It works similarly, just a different syntax.

BIND Zones
Copy link

Basic DNS server setup is complete. Now, let’s talk about usage. For that, you configure zones:

  • Primary zone – You create and edit domain records directly on this host.
  • Secondary zone – This host pulls data from a primary DNS server.
  • Stub zone – Stores only NS records used for redirection.
  • Caching-only zone – Doesn’t store records; only caches query results for performance.

Zone management is handled in the config file and is a larger topic. Creating your own zone lets you assign friendly names to each host, which is helpful when dealing with many nodes instead of using IPs.

And if you’re looking for a reliable, high-performance, and budget-friendly solution for your workflows, Hostman has you covered with Linux VPS Hosting options, including Debian VPS, Ubuntu VPS, and VPS CentOS.