25. DNS Server
The Domain Name System (DNS) is a hierarchical, distributed, and scalable naming database. Often referred to as the “phonebook of the internet”, it translates human-friendly domain names (like api.example.com) into machine-routable IP addresses (192.0.2.1 or 2001:db8::1). In modern microservices, cloud VPCs, and Kubernetes clusters, robust DNS resolution is fundamental to service discovery.
25.1 DNS Hierarchy & Architecture
Section titled “25.1 DNS Hierarchy & Architecture”DNS is structured into an inverted tree hierarchy:
. (Root Zone) ↓ Top-Level Domains (.com, .org, .net, .io, .in) ↓ Second-Level Domains (example.com) ↓ Subdomains (api.example.com, mail.example.com)- Root Level (
.): The apex of the DNS tree, maintained by 13 root server clusters globally. - Top-Level Domains (TLDs):
- Generic TLDs (gTLDs):
.com,.org,.net,.edu - Country Code TLDs (ccTLDs):
.in,.uk,.de,.jp
- Generic TLDs (gTLDs):
- Second-Level Domains: The domain registered by an organization (e.g.,
example.com). - Subdomains: Delegated branches used for specific services or environments (e.g.,
dev.api.example.com).
25.2 The 9-Stage DNS Resolution Process
Section titled “25.2 The 9-Stage DNS Resolution Process”When a client navigates to https://www.example.com, the system resolves the hostname step-by-step:
1. Client Request ↓ 2. Browser Cache Check ──(Found)──► [Connect to IP] ↓ (Miss) 3. OS Local Cache Check ──(Found)──► [Connect to IP] ↓ (Miss) 4. Query Recursive Resolver (ISP / 8.8.8.8) ↓ 5. Root Name Server ──► Refers to .com TLD Server ↓ 6. TLD Name Server ──► Refers to example.com Authoritative Server ↓ 7. Authoritative Server ──► Returns IP: 192.168.1.50 ↓ 8. Resolver Caches & Returns IP to Client OS / Browser ↓ 9. Client Establishes Connection to Target Server25.3 Types of DNS Servers & Roles
Section titled “25.3 Types of DNS Servers & Roles”| Server Type | Operational Role |
|||
| Recursive Resolver | Interacts directly with client devices; performs the iterative queries across the hierarchy and caches results |
| Root Name Server | Directs queries to the authoritative TLD nameservers |
| TLD Name Server | Manages registry information for specific extensions (.com, .org) and points to domain authoritative servers |
| Authoritative Name Server | Holds the definitive zone database files for a specific domain; the ultimate source of truth |
| Forwarding DNS Server | Forwards queries to upstream DNS resolvers rather than performing full recursion |
| Caching-Only DNS Server | Caches previous query results to accelerate lookups on local networks without hosting zones |
| Primary (Master) Server | Holds the original read/write master copy of zone files |
| Secondary (Slave) Server | Replicates read-only zone files from the master via DNS zone transfers for high availability |
25.4 DNS Record Types Reference
Section titled “25.4 DNS Record Types Reference”| Record | Name | Purpose | Example |
|||||
| A | Address | Maps an IPv4 address to a hostname | web.example.com. IN A 192.168.1.50 |
| AAAA | IPv6 Address | Maps an IPv6 address to a hostname | web.example.com. IN AAAA 2001:db8::50 |
| CNAME | Canonical Name | Creates an alias pointing to another hostname | www.example.com. IN CNAME web.example.com. |
| MX | Mail Exchange | Specifies mail servers responsible for receiving email | example.com. IN MX 10 mail.example.com. |
| NS | Name Server | Delegates a zone to authoritative nameservers | example.com. IN NS ns1.example.com. |
| TXT | Text | Stores arbitrary verification strings (SPF, DKIM, DMARC) | example.com. IN TXT "v=spf1 include:_spf.google.com ~all" |
| SOA | Start of Authority | Defines authoritative zone metadata, contact email, and serial | Sets refresh, retry, and expiration timers |
| PTR | Pointer | Reverse DNS: maps an IP address back to a hostname | 50.1.168.192.in-addr.arpa. IN PTR web.example.com. |
| SRV | Service Record | Identifies hostname and port for specific services (SIP, LDAP) | _sip._tcp.example.com. IN SRV 10 60 5060 bigbox.example.com. |
| CAA | Cert Authority Auth | Specifies which Certificate Authorities can issue SSL certs | example.com. IN CAA 0 issue "letsencrypt.org" |
25.5 Protocols, Ports & Security
Section titled “25.5 Protocols, Ports & Security”Port 53: UDP vs TCP
Section titled “Port 53: UDP vs TCP”- UDP Port 53: Used for the vast majority of standard DNS queries. It is lightweight, stateless, and fast.
- TCP Port 53: Required when response payloads exceed 512 bytes (extended by EDNS0) and for DNS Zone Transfers (
AXFR/IXFR) between Master and Slave servers. Both UDP and TCP port 53 must be open in firewalls.
Modern DNS Security Protocols
Section titled “Modern DNS Security Protocols”- DNSSEC (DNS Security Extensions): Adds cryptographic digital signatures to DNS records to verify authenticity and prevent DNS spoofing and cache poisoning.
- DoH (DNS over HTTPS): Encrypts DNS traffic over HTTPS (TCP port 443) to prevent eavesdropping and ISP manipulation.
- DoT (DNS over TLS): Encrypts raw DNS packets using TLS over a dedicated port (TCP port 853).
Common Security Threats
Section titled “Common Security Threats”- Cache Poisoning / Spoofing: Infiltrating false IP mappings into a resolver’s cache to redirect users to malicious clones.
- DNS Tunneling: Encapsulating non-DNS protocols inside DNS queries to exfiltrate data past corporate firewalls.
- DDoS Amplification: Flooding open recursive resolvers with spoofed source IPs to overwhelm a victim host.
25.6 Setting Up an Authoritative & Caching BIND Server
Section titled “25.6 Setting Up an Authoritative & Caching BIND Server”BIND (Berkeley Internet Name Domain) is the industry standard open-source DNS server on Linux.
1. Installation
Section titled “1. Installation”- Ubuntu / Debian:
Terminal window sudo apt update && sudo apt install bind9 bind9utils bind9-doc -y# Optional: Force IPv4 only by editing /etc/default/named:# OPTIONS="-u bind -4"sudo systemctl enable --now bind9 - RHEL / Rocky / AlmaLinux:
Terminal window sudo dnf install bind bind-utils -ysudo systemctl enable --now named
2. Main Server Options (named.conf)
Section titled “2. Main Server Options (named.conf)”- On Ubuntu:
/etc/bind/named.conf.options - On RHEL:
/etc/named.conf
options { directory "/var/cache/bind"; # (On RHEL: "/var/named")
listen-on port 53 { 127.0.0.1; 192.168.1.10; }; listen-on-v6 { any; };
# Access control: allow queries from internal subnet only allow-query { localhost; 192.168.1.0/24; };
# Upstream forwarders for external queries forwarders { 1.1.1.1; 8.8.8.8; };
recursion yes; dnssec-validation auto;};25.7 Defining Forward and Reverse Zones
Section titled “25.7 Defining Forward and Reverse Zones”1. Zone Declarations
Section titled “1. Zone Declarations”Add zone definitions to /etc/bind/named.conf.local (Ubuntu) or /etc/named.rfc1912.zones (RHEL):
// Forward Zone: maps domain names to IP addresseszone "ops.internal" IN { type master; file "/etc/bind/zones/db.ops.internal";};
// Reverse Zone: maps IP addresses to domain nameszone "1.168.192.in-addr.arpa" IN { type master; file "/etc/bind/zones/db.192.168.1";};2. Forward Zone File (db.ops.internal)
Section titled “2. Forward Zone File (db.ops.internal)”$TTL 86400@ IN SOA ns1.ops.internal. admin.ops.internal. ( 4 ; Serial (increment after changes!) 604800 ; Refresh (1 week) 86400 ; Retry (1 day) 2419200 ; Expire (4 weeks) 86400 ) ; Minimum TTL
; Authoritative Name Servers@ IN NS ns1.ops.internal.
; A Recordsns1 IN A 192.168.1.10gw IN A 192.168.1.1web01 IN A 192.168.1.50db01 IN A 192.168.1.60
; CNAME Recordswww IN CNAME web01.ops.internal.api IN CNAME web01.ops.internal.3. Reverse Zone File (db.192.168.1)
Section titled “3. Reverse Zone File (db.192.168.1)”$TTL 86400@ IN SOA ns1.ops.internal. admin.ops.internal. ( 4 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 86400 ) ; Minimum TTL
; Authoritative Name Servers@ IN NS ns1.ops.internal.
; PTR Records (Last octet of the IP)10 IN PTR ns1.ops.internal.1 IN PTR gw.ops.internal.50 IN PTR web01.ops.internal.60 IN PTR db01.ops.internal.25.8 Testing, Validating & Client Configuration
Section titled “25.8 Testing, Validating & Client Configuration”1. Validate Syntax Before Restarting
Section titled “1. Validate Syntax Before Restarting”# Validate main configuration filesudo named-checkconf
# Validate forward zone filesudo named-checkzone ops.internal /etc/bind/zones/db.ops.internal
# Validate reverse zone filesudo named-checkzone 1.168.192.in-addr.arpa /etc/bind/zones/db.192.168.1
# Reload BINDsudo systemctl restart named # or 'bind9' on Ubuntu2. Firewall Rules
Section titled “2. Firewall Rules”# Firewalld:sudo firewall-cmd --permanent --add-service=dnssudo firewall-cmd --reload
# UFW:sudo ufw allow 53/tcpsudo ufw allow 53/udp3. Configuring Clients to Use the DNS Server
Section titled “3. Configuring Clients to Use the DNS Server”- Ubuntu (Netplan
/etc/netplan/*.yaml):Apply with:network:version: 2ethernets:eth0:nameservers:addresses: [192.168.1.10]search: [ops.internal]sudo netplan apply. - RHEL (NetworkManager
nmcli):Terminal window sudo nmcli con mod eth0 ipv4.dns "192.168.1.10"sudo nmcli con up eth0
4. Query Testing
Section titled “4. Query Testing”# Query the local DNS server directlydig @192.168.1.10 web01.ops.internal +short
# Reverse lookup querydig @192.168.1.10 -x 192.168.1.50 +short