DNS Fundamentals
The Domain Name System (DNS) is a hierarchical, distributed naming system that translates human-readable domain names (like example.com) into IP addresses (like 93.184.216.34). It is one of the foundational services of the internet, enabling almost all network communication.
Why DNS Exists
Computers communicate using IP addresses, but humans find domain names easier to remember. DNS provides a mapping between the two, with additional capabilities like mail routing, service discovery, and verification records.
Before DNS, a single file called /etc/hosts mapped hostnames to IP addresses. As the internet grew, this file became unmanageable. DNS replaced it with a scalable, distributed database.
How DNS Works
When you type example.com in a browser, the following happens:
- The operating system checks
/etc/hostsand the local DNS cache. - If not found, a query is sent to a recursive resolver (usually provided by your ISP or configured manually).
- The resolver queries the root nameservers for the
.comTLD. - The resolver queries the
.comTLD nameservers forexample.com. - The resolver queries
example.com's authoritative nameservers for the IP address. - The resolver returns the answer to the client, which caches it for future use.
DNS Zones and Hierarchy
The DNS namespace is a tree structure:
- Root zone (
.): The top of the hierarchy, served by 13 root server names (technically many more physical servers via anycast). - Top-Level Domains (TLDs):
.com,.org,.net, country codes (.uk,.de), and new gTLDs (.dev,.io). - Second-Level Domains:
example.com,google.com. - Subdomains:
mail.example.com,api.example.com.
A zone is a contiguous portion of the DNS namespace managed by a single authority. Zones are delegated from parent to child. The parent zone contains NS records pointing to the child's nameservers.
DNS Record Types
Address Records
- A: Maps a hostname to an IPv4 address.
- AAAA: Maps a hostname to an IPv6 address.
Alias and Redirection
- CNAME: Canonical Name. Maps an alias to another hostname.
- ALIAS: Non-standard record (supported by some providers) that maps to an A record at the resolver level.
Mail Records
- MX: Mail Exchange. Specifies the mail server for a domain, with a priority value.
- TXT: Arbitrary text, used for SPF, DKIM, DMARC, and verification.
- SRV: Service record, specifying host and port for a service (e.g., SIP, XMPP).
Other Records
- NS: Nameserver. Delegates a zone to nameservers.
- PTR: Pointer. Maps an IP address to a hostname (reverse DNS).
- SOA: Start of Authority. Contains zone metadata (serial, refresh, retry, expire, minimum TTL).
- CAA: Certification Authority Authorization. Specifies which CAs can issue certificates for a domain.
- DNSKEY/DS/RRSIG: Used for DNSSEC authentication.
DNS Resolution Flow
The resolver configuration on Linux is typically in /etc/resolv.conf:
nameserver 1.1.1.1 nameserver 8.8.8.8 search example.com options timeout:2 attempts:3
Modern systems may use systemd-resolved, which maintains its own cache and manages /etc/resolv.conf.
DNS Servers
Several DNS server implementations exist:
- BIND: The original and most widely used DNS server. Feature-complete but complex.
- systemd-resolved: Integrated with systemd, provides caching and split DNS.
- dnsmasq: Lightweight DNS forwarder and DHCP server. Ideal for small networks. See Article - DNS - dnsmasq.
- CoreDNS: CNCF-certified DNS server popular in Kubernetes. See Article - DNS - coredns.
- Unbound: Validating, recursive, caching DNS resolver. Focus on security and performance.
- Knot DNS: Authoritative server from CZ.NIC, designed for high performance and DNSSEC.
Zone File Example
A simple zone file for example.com:
$ORIGIN example.com.
$TTL 3600
@ IN SOA ns1.example.com. admin.example.com. (
2024010101 ; serial
3600 ; refresh
1800 ; retry
604800 ; expire
3600 ) ; minimum
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
@ IN A 93.184.216.34
@ IN AAAA 2606:2800:220:1:248:1893:25c8:1946
@ IN MX 10 mail.example.com.
www IN A 93.184.216.34
mail IN A 93.184.216.35
Related Articles
- dnsmasq: Article - DNS - dnsmasq
- CoreDNS: Article - DNS - coredns
- OSI model: Article - OSI network model
- Protocols: Article - Main protocols: ARP, ICMP, UDP, TCP