Setting Up a DNS Server
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:
- Order another public IP address — DNS setup requires at least two IPs.
- Open DNS port 53, which is necessary for the nameserver to work.
Ubuntu/Debian
Update the package list:
apt updateAllow incoming packets on port 53 UDP in the firewall:
iptables -I INPUT -p udp --dport 53 -j ACCEPTSave the firewall rules:
iptables-saveCentOS
Install system updates:
yum updateInstall time synchronization utility:
yum install chronySet your timezone, for example:
timedatectl set-timezone Europe/CyprusEnable and start the time synchronization service:
systemctl enable chronyd --nowOpen port 53:
firewall-cmd --permanent --add-port=53/udpApply the updated firewall rules:
firewall-cmd --reloadInstalling 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 dnsutilsEnable autostart:
systemctl enable bind9Start the service:
systemctl start bind9Check if it's running:
systemctl status bind9Look for active status in the output.
CentOS
Install the DNS utility:
yum install bindEnable autostart:
systemctl enable namedStart the service:
systemctl start namedCheck its status:
systemctl status namedYou 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.optionsIn 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 bind9CentOS
Open the config file:
vi /etc/named.confFind 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 namedGlobal Options Copy link
Besides the basics, you can fine-tune the server using other global parameters:
|
Argument |
What It Configures |
|
|
Working directory (default is |
|
|
IPs to forward unresolved queries to (e.g., Google's DNS)
|
|
|
Options: |
|
|
Interfaces that |
|
|
Hosts allowed for zone transfers |
|
|
Who is allowed to send DNS queries |
|
|
Hosts allowed to receive zone change notifications |
|
|
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.14This 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.comIt 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.