1. The Domain Name System (DNS) Architecture
DNS Hierarchy
The Domain Name System (DNS) is the phonebook of the internet. It translates human-readable hostnames like voidx.academy into IP addresses computers understand. The architecture is hierarchical, starting at the root zone (represented by the dot "."), moving down to Top-Level Domains (TLDs) like .com or .org, and finally to Authoritative Name Servers which hold the actual records for specific domains.
When a request is made, a Recursive Resolver acts as the intermediary, traversing this hierarchy to fetch the data. If the information isn't cached, it queries the Root Server for the TLD location, the TLD server for the Authoritative server location, and the Authoritative server for the final address.
You can visualize this trace using the dig command with the +trace flag. This simulates the traversal process exactly.
. is implicitly present at the end of every FQDN.
dig +trace voidx.academy
DNS Record Types
DNS stores information in resource records (RRs). Each type serves a distinct purpose in network traffic routing and security.
The following table summarizes common record types used in daily network operations.
| Type | Function |
|---|---|
| A | IPv4 Mapping |
| AAAA | IPv6 Mapping |
| CNAME | Canonical Name alias |
| TXT | Arbitrary text, used for SPF/DKIM |
dig TXT google.com
Iterative vs Recursive Queries
A Recursive query instructs the name server to perform all the heavy lifting to find the answer. If the server does not know, it queries other servers until it finds the result or returns an error.
An Iterative query is a 'best effort' response. The server provides the best answer it currently has, or provides a referral to another server that might know better, without performing further lookups itself.
Most client-to-resolver communication is recursive, while server-to-server communication is iterative.
import socket def check_recursion(): # Example of a standard recursive query socket setup s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP Port 53 is the standard DNS port print('DNS resolver socket initialized for recursive query.') check_recursion()
Inspecting DNS Message Format
DNS messages use a fixed format regardless of query or response. The Header section is 12 bytes and contains flags, question counts, and answer counts.
Following the header are the Question, Answer, Authority, and Additional sections. Using Python's struct module, we can unpack raw bytes captured from a network dump to see exactly how these fields are structured.
This is essential for identifying anomalous DNS traffic, such as data exfiltration hidden within large DNS query packets.
import struct def decode_header(data): # DNS header is 12 bytes: ID, Flags, QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT header = struct.unpack('!HHHHHH', data[:12]) print(f'Transaction ID: {hex(header[0])}') print(f'Question Count: {header[2]}') # Mock DNS header bytes mock_bytes = b'\xaa\xbb\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00' decode_header(mock_bytes)
Knowledge Check
Ready to test your understanding of 1. The Domain Name System (DNS) Architecture?