30 Mins

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.

Security Operator Note: Always remember that the DNS root . is implicitly present at the end of every FQDN.
Text
dig +trace voidx.academy
DNS Resolution Flow • Iterative & Recursive Hierarchy Lookup
1. RECURSIVE RESOLVER 8.8.8.8 Checks Cache & Probes Hierarchy
2. ROOT SERVER . (Root) Points to .academy TLD
3. TLD SERVER .academy Points to voidx NS
4. AUTHORITATIVE NS ns1.voidx.academy Returns A Record: 104.21.5.88

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.

TypeFunction
AIPv4 Mapping
AAAAIPv6 Mapping
CNAMECanonical Name alias
TXTArbitrary text, used for SPF/DKIM
Security Operator Note: TXT records are frequently abused for command-and-control (C2) beaconing in malware scenarios.
Text
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.

Security Operator Note: If a recursive resolver is misconfigured to allow external queries, it can be exploited for DNS amplification DDoS attacks.
Python 3
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.

Security Operator Note: Always verify the Transaction ID in a DNS response matches your request to prevent cache poisoning.
Python 3
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?

Back