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.
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:
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
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
This guide uses BIND 9 to create an IP-based DNS server.
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.
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.
The settings are defined in the configuration file.
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
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
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. |
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.
Basic DNS server setup is complete. Now, let’s talk about usage. For that, you configure zones:
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.