How to Build a Full‑Featured DNS Server on Linux (Step‑by‑Step Guide)
This article walks you through configuring a Linux DNS server with BIND, covering DNS fundamentals, server setup, named.conf options, forward and reverse zone definitions, record creation, client testing, and troubleshooting tips, all illustrated with code snippets and screenshots.
Introduction
Setting up a DNS server on Linux involves installing and configuring software that translates domain names to IP addresses, enabling users to access resources via memorable names.
Where does DNS get IP addresses?
Local cache: The server stores previously queried domain‑IP pairs for faster responses.
Recursive query: If the cache misses, the server queries root servers, then top‑level domain servers, and finally authoritative servers until it obtains the address.
Forwarding: Unresolved queries can be forwarded to upstream DNS servers, such as those provided by an ISP.
Functions of DNS
Domain resolution: Converts domain names to IP addresses for browsers.
Load balancing: Returns different IPs for the same domain to distribute traffic.
Email routing: Provides MX records to locate mail servers.
Security: DNSSEC can protect against DNS hijacking.
Other services: Supports reverse lookup, dynamic updates, and domain registration.
1. Server Configuration
Configure IP, disable firewall and SELinux, then install BIND:
yum install bind -y2. Edit Configuration Files
The main configuration file is /etc/named.conf. Key options include:
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; };
};Define Forward Zone
zone "example.com" IN {
type master;
file "example.com.zone";
allow-update { none; };
};Define Reverse Zone
zone "180.168.192.in-addr.arpa" IN {
type master;
file "example.com.arpa";
allow-update { none; };
};Modify Zone Files (Key Step)
Copy template files and edit them:
cp -p named.empty example.com.zone
cp -p named.empty example.com.arpaIn example.com.zone add records such as:
example.com. IN SOA root.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.44In 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.3. Client Testing
Configure the client’s /etc/resolv.conf to point to the DNS server’s IP, then test forward and reverse lookups. Successful tests confirm that the zone files and records are correctly applied.
Notes
If the service fails to start, check the configuration syntax with: named-checkconf /etc/named.conf Review systemctl status named.service and journalctl -xe for error details, then correct any mistakes in named.conf or zone files.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
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.
