Skip to content

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.

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
  • 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).

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 Server

| 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 |

| 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" |

  • 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.
  • 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).
  • 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.

  • 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 -y
    sudo systemctl enable --now named
  • 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;
};

Add zone definitions to /etc/bind/named.conf.local (Ubuntu) or /etc/named.rfc1912.zones (RHEL):

// Forward Zone: maps domain names to IP addresses
zone "ops.internal" IN {
type master;
file "/etc/bind/zones/db.ops.internal";
};
// Reverse Zone: maps IP addresses to domain names
zone "1.168.192.in-addr.arpa" IN {
type master;
file "/etc/bind/zones/db.192.168.1";
};
$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 Records
ns1 IN A 192.168.1.10
gw IN A 192.168.1.1
web01 IN A 192.168.1.50
db01 IN A 192.168.1.60
; CNAME Records
www IN CNAME web01.ops.internal.
api IN CNAME web01.ops.internal.
$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”
Terminal window
# Validate main configuration file
sudo named-checkconf
# Validate forward zone file
sudo named-checkzone ops.internal /etc/bind/zones/db.ops.internal
# Validate reverse zone file
sudo named-checkzone 1.168.192.in-addr.arpa /etc/bind/zones/db.192.168.1
# Reload BIND
sudo systemctl restart named # or 'bind9' on Ubuntu
Terminal window
# Firewalld:
sudo firewall-cmd --permanent --add-service=dns
sudo firewall-cmd --reload
# UFW:
sudo ufw allow 53/tcp
sudo ufw allow 53/udp

3. Configuring Clients to Use the DNS Server

Section titled “3. Configuring Clients to Use the DNS Server”
  • Ubuntu (Netplan /etc/netplan/*.yaml):
    network:
    version: 2
    ethernets:
    eth0:
    nameservers:
    addresses: [192.168.1.10]
    search: [ops.internal]
    Apply with: sudo netplan apply.
  • RHEL (NetworkManager nmcli):
    Terminal window
    sudo nmcli con mod eth0 ipv4.dns "192.168.1.10"
    sudo nmcli con up eth0
Terminal window
# Query the local DNS server directly
dig @192.168.1.10 web01.ops.internal +short
# Reverse lookup query
dig @192.168.1.10 -x 192.168.1.50 +short