Course contentsShow
← Computer Science
Lesson 1512 of 2,87235. Application Layer ProtocolsFree lesson

DNS Protocol and Message Format

Learning the structure of DNS messages including headers, questions, answers, authority, and additional sections over UDP port 53.

DNS Protocol and Message Format

You'll learn how DNS messages are actually structured and exchanged between clients and servers.

What DNS Messages Look Like

When your computer asks a DNS server "What's the IP for example.com?" or when a server replies, they speak using a specific binary message format over UDP port 53 (occasionally TCP for larger responses). Think of it like a standardized form with labeled boxes—both sides know exactly where to read and write information.

DNS Message Structure

Every DNS message has five sections, always in this order:

1. Header (12 bytes)

Contains metadata: a unique query ID, flags (Is this a query or response? Recursive? Authoritative?), and counts of entries in the following sections.

2. Question Section

Lists what you're asking about—typically one domain name and the record type you want (A, AAAA, MX, etc.). "What's the A record for example.com?"

3. Answer Section

Contains the resource records that directly answer your question. Empty in queries; filled in responses.

4. Authority Section

Lists nameserver records (NS) that have authority over the domain. Used when the responding server doesn't have the final answer but knows who does.

5. Additional Section

Provides helpful extra information, like the IP addresses of nameservers mentioned in the Authority section—saves you follow-up queries.

Why UDP Port 53?

DNS prioritizes speed over guaranteed delivery. Most queries/responses fit in a single UDP datagram (512 bytes traditionally), making DNS fast and efficient. For oversized responses, DNS falls back to TCP.

Key Takeaway: DNS messages follow a five-section format (Header, Question, Answer, Authority, Additional) transmitted primarily over UDP port 53, enabling fast domain name resolution through structured binary communication.