Step-by-Step Guide to Building a DNS Server on Linux
Learn how to configure a full-featured DNS server on Linux, covering DNS fundamentals, local caching, recursive and forward queries, BIND installation, detailed named.conf settings, zone file creation for forward and reverse lookups, and client testing, with troubleshooting tips and common pitfalls.
Overview
Domain Name System (DNS) translates human‑readable domain names into IP addresses, enabling users to access services without memorizing numeric addresses. This guide explains how to set up a DNS server on Linux, covering caching, recursive queries, and both forward and reverse lookups.
Prerequisites
Install the BIND package, disable the firewall and SELinux, and ensure the server has a static IP address.
yum install bind -yConfigure named.conf
Edit /etc/named.conf and set the global options.
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; };
};Explanation of key options
listen-on port 53 { any; }: Accept DNS queries on the standard port from any IPv4 address.
listen-on-v6 port 53 { ::1; }: Accept queries on IPv6 loopback only.
directory "/var/named": Directory where zone files are stored.
allow-query { any; }: Permit any client to query the server.
Define forward zone
Create a forward zone for example.com:
zone "example.com" IN {
type master;
file "example.com.zone";
allow-update { none; };
};In example.com.zone add resource records:
example.com. IN NS dns.example.com.
dns IN A 192.168.180.188
www IN A 192.168.180.189
exam IN A 192.168.180.190
ftp IN A 192.168.180.191
sun IN A 192.168.180.44Define reverse zone
Create a reverse zone for the 192.168.180.0/24 network:
zone "180.168.192.in-addr.arpa" IN {
type master;
file "example.com.arpa";
allow-update { none; };
};In example.com.arpa add PTR records:
@ IN NS dns.example.com.
188 IN PTR dns.example.com.
189 IN PTR www.example.com.
190 IN PTR exam.example.com.
191 IN PTR ftp.example.com.
44 IN PTR sun.example.com.Client configuration and testing
On a client machine, edit /etc/resolv.conf to point to the DNS server: nameserver 192.168.180.188 Test forward resolution: dig www.example.com Test reverse resolution:
dig -x 192.168.180.189Common issues
If the named service fails to start, verify the configuration syntax: named-checkconf /etc/named.conf Check the service status and logs with systemctl status named and journalctl -xe. Ensure all zone files end with a trailing dot and that the files referenced in named.conf exist.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
