---
title: "DNS request/response structure"
subject: "Computer Networks and Security"
chapter: 6
key: "semester_7/computer_networks_and_security:dns-request-response"
source: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/dns-request-response
site: BCT Engineering
---

# DNS request/response structure

Computer Networks and Security · Chapter 6: Application Layer

- Asked in: 2071 Chaitra, 2+6 marks
- Video: ["Understanding DNS Packets: Exploring DNS Query and Response Messages"](https://www.youtube.com/watch?v=zDvPT1shDFg) — TechClout
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/dns-request-response
- Whole chapter: https://www.bctengineer.com/md/semester_7/computer_networks_and_security/chapter-6

## Question

What is DNS? Explain the structure of DNS request and response with a practical example.

## Short answer

DNS messages have a 12-byte header (ID, flags, counts) followed by question, answer, authority, and additional sections. Flags indicate query/response, recursion, and error codes. Example: query for www.example.com A record returns answer with IP 93.184.216.34 and TTL 3600. Tools like dig display this exchange.

## Answer

**DNS (Domain Name System)** is the distributed, hierarchical naming system that maps domain names to IP addresses. A request and its response use the **same message format**, carried in a UDP datagram on port 53.

#### DNS message structure
```text
+----------------+----------------------+
| Identification | Flags                |  12-byte
+----------------+----------------------+  header
| # Questions    | # Answer RRs         |
+----------------+----------------------+
| # Authority RRs| # Additional RRs     |
+----------------+----------------------+
| Question section (name, type, class)  |
| Answer section (resource records)     |
| Authority section (NS records)        |
| Additional section (extra records)    |
+---------------------------------------+
```

- **Identification (16 bits):** matches a response with its query.
- **Flags (16 bits):** QR (0 query, 1 response), Opcode, AA (authoritative answer), TC (truncated), RD (recursion desired), RA (recursion available), RCODE (0 no error, 3 name does not exist).
- **Counts:** number of entries in each following section.
- **Question:** the name queried, type (A, MX ...) and class (IN).
- **Answer / Authority / Additional:** resource records (name, type, class, TTL, length, data).

#### Practical example: resolving www.example.com
**Query** (client to resolver):
```text
ID = 0xABCD   QR=0  RD=1
Questions = 1
Question: www.example.com  Type=A  Class=IN
```
**Response:**
```text
ID = 0xABCD   QR=1  AA=0  RD=1  RA=1  RCODE=0
Questions = 1, Answers = 1
Question: www.example.com  A  IN
Answer  : www.example.com  A  IN  TTL=3600  93.184.216.34
```
The client matches the ID, takes the IP address, and connects to the web server. The resolver caches the answer for 3600 s. The command `nslookup www.example.com` or `dig www.example.com` shows this exchange.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How do DNS request and response differ in format?
   A. They use the same message format
   B. Different formats
   C. Request uses TCP only
   D. Response has no header
   Answer: A. Both use the same format, carried in UDP port 53. (Key point: Message format)

2. What is the Identification field for?
   A. Matching a response with its query
   B. Counting answers
   C. Setting TTL
   D. Storing class
   Answer: A. The 16-bit ID matches response to query. (Key point: Identification)

3. What does the QR flag value 1 mean?
   A. Query
   B. Response
   C. Recursion desired
   D. Truncated
   Answer: B. QR=0 is query, QR=1 is response. (Key point: QR flag)

## Related in other subjects

- [Stateful/stateless and DNS working](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Astateful-dns-example) — Distributed System, chapter 2
- [Filter importance in communication; ideal vs practical](https://www.bctengineer.com/question.md?key=semester_5%2Ffilter_design%3Afilter-communication-ideal-practical) — Filter Design, chapter 1, asked 2×
