Every web page begins with a DNS lookup. This article walks through the DNS protocol — the message types, the header and record layout, and the exact point in a browsing session where a name is turned into an IP address.
The Domain Name System (DNS) translates a human-readable name such as www.example.com into the IP
address a computer actually connects to. It is the very first network step of loading a page: nothing else can happen
until the name resolves. The diagram below shows the order of operations when a browser opens an HTTPS site.
Before a query even leaves the machine, the resolver checks local sources in order — the browser’s own
cache, the operating system’s DNS cache, and the hosts file. Only on a miss does the stub resolver
send a DNS query to the configured recursive resolver, which may in turn walk the DNS hierarchy (root →
top-level domain → authoritative server) to find the answer.
Queries and responses use the same message format, defined in RFC 1035. A message has a fixed 12-byte header followed by four variable-length sections. The header’s count fields say how many entries each section holds.
The 12-byte header is six 16-bit words. The second word holds the flag bits that distinguish a query from a response and report the outcome; the last four words are the section counts.
There is one wire format, but the header tells you what a message is. The QR bit says whether
it is a query or a response, the Opcode says what kind of operation it is, and on a response the
RCODE reports the outcome.
| Header field | Common values | Meaning |
|---|---|---|
| QR | 0 / 1 | Query (a question) or response (an answer) |
| Opcode | QUERY (0), STATUS (2), NOTIFY (4), UPDATE (5) | What kind of request this is — an ordinary lookup, a server status check, a zone-change notification, or a dynamic update |
| RCODE | NOERROR (0), FORMERR (1), SERVFAIL (2), NXDOMAIN (3), NOTIMP (4), REFUSED (5) | Result reported in a response — success, a malformed query, server failure, a non-existent name, an unsupported operation, or a refusal |
The Answer, Authority and Additional sections are all built from resource records (RRs). Every RR has the same shape: a name, a type and class, a time-to-live, and a length-prefixed blob of record data.
The TYPE field decides how to read RDATA. These are the record types you meet most often:
| Type | Value | What it returns |
|---|---|---|
| A | 1 | An IPv4 address |
| AAAA | 28 | An IPv6 address |
| CNAME | 5 | A canonical (alias) name pointing to another name |
| NS | 2 | An authoritative name server for the zone |
| MX | 15 | A mail server name plus a priority |
| TXT | 16 | Arbitrary text (SPF, domain-ownership verification, etc.) |
| PTR | 12 | A name for a reverse (IP-to-name) lookup |
| SOA | 6 | The start-of-authority record describing a zone |
| SRV | 33 | The host and port of a named service |
| CAA | 257 | Which certificate authorities may issue certs for the domain |
DNS usually rides on UDP port 53, because a single small datagram each way is fast and cheap. If a
reply is too large for a UDP datagram, the server sets the TC (truncated) flag and the client retries
the same query over TCP port 53. TCP is also used for zone transfers between servers. Encrypted
variants wrap DNS to keep lookups private in transit: DNS over TLS (DoT, port 853) and
DNS over HTTPS (DoH, port 443).
Putting it together, here is a query for the A record of www.example.com and the response that comes
back, with the header fields shown alongside the sections they describe:
The header’s id ties the answer to the question; qr marks it as a response;
status: NOERROR is RCODE 0; and the counts say there is one question and one answer. In the answer
record you can read the TTL (86400 seconds), the class (IN), the type (A) and
the RDATA (the IPv4 address).
A host-based DNS firewall works by reading these exact fields as messages pass through the machine. DNS Proxywall sits at steps 1–2 of the browsing sequence and acts on the protocol directly:
DNS Proxywall reads, filters, caches and proxies these messages on Windows — as a DNS firewall and a DNS proxy in one.
Notes:
* Windows® is a registered trademark of the Microsoft Corporation.