Understanding DNS Lookup and dig Command Output — A Complete Guide with Examples

REF: AI Tools/ChatGPT


🧠 Understanding DNS Lookup and dig Command Output — A Complete Guide with Examples

If you’ve ever used the internet, you’ve used DNS — even if you didn’t know it. The Domain Name System (DNS) converts human-friendly names like www.example.com into IP addresses like 93.184.216.34.
Let’s explore how a DNS lookup works using the dig command, and understand each section of the DNS response: header, question, answer, authority, additional, flags, and more.


🔍 DNS Lookup: dig Command Output

The dig (Domain Information Groper) command is one of the most powerful tools for testing and analyzing DNS lookups.

🧭 Example Command

dig www.example.com

🧩 Typical Output (Explained)

; <<>> DiG 9.18.1-1ubuntu1.3-Ubuntu <<>> www.example.com
;; global options: +cmd

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

;; QUESTION SECTION:
;www.example.com.           IN      A

;; ANSWER SECTION:
www.example.com.    3600    IN      A       93.184.216.34

;; AUTHORITY SECTION:
example.com.        172800  IN      NS      a.iana-servers.net.
example.com.        172800  IN      NS      b.iana-servers.net.

;; ADDITIONAL SECTION:
a.iana-servers.net. 172800  IN      A       199.43.135.53
b.iana-servers.net. 172800  IN      A       199.43.133.53
a.iana-servers.net. 172800  IN      AAAA    2001:500:8f::53

;; Query time: 25 msec
;; SERVER: 192.168.56.10#53(192.168.56.10)
;; WHEN: Tue Oct 08 10:12:44 EDT 2025
;; MSG SIZE  rcvd: 210

🧱 Breakdown by Sections

SectionMeaningExample / Explanation
HEADERMetadata about the query and server responsestatus: NOERROR → successful lookup. Flags show query type and recursion status.
QUESTION SECTIONWhat was askedwww.example.com. IN A → asking for IPv4 address.
ANSWER SECTIONThe direct answerwww.example.com. 3600 IN A 93.184.216.34 → host IP address.
AUTHORITY SECTIONWhich servers are authoritative for the zoneexample.com. IN NS a.iana-servers.net.
ADDITIONAL SECTIONSupplementary info (IPs of NS records)Lists A and AAAA records of the name servers.
FOOTERTiming, query server, and message sizeSERVER: 192.168.56.10#53 shows which DNS server responded.

⚙️ Dig Command Details

Sometimes your dig output might look different. This depends on options, configuration, or empty sections.

Why You Might Not See All Sections

  • Some dig versions suppress empty sections.
  • A .digrc file might set defaults like +short or +noall.
  • Flags like +short simplify the output.

✅ Show All Sections Explicitly

dig www.example.com +noall +answer +authority +additional +comments

Or, for a recursive trace:

dig www.example.com +trace

To check if .digrc is hiding sections:

cat ~/.digrc

📦 Additional Section Explained

The Additional Section provides helpful data such as the IP addresses of the name servers listed in the Authority Section.

Example:

Authority Section:

example.com.  IN  NS  a.iana-servers.net.

Additional Section:

a.iana-servers.net. IN A 199.43.135.53

This saves time by avoiding another DNS lookup.

Command to show it:

dig example.com +noall +answer +authority +additional +comments

🧩 DNS Message Structure

Every DNS message (query or response) has the same structure:

  1. Header (12 bytes)
  2. Question Section
  3. Answer Section
  4. Authority Section
  5. Additional Section

DNS Header Format

FieldSize (bits)Description
ID16Identifier to match queries and responses
Flags16Operation and response flags
QDCOUNT16Number of questions
ANCOUNT16Number of answers
NSCOUNT16Number of authority records
ARCOUNT16Number of additional records

Example Header:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

🚩 DNS Flag Details

Flags define how the message behaves and what the result means.

FlagBit(s)MeaningExample
QR00 = Query, 1 = ResponseResponse has QR=1
Opcode1–4Query typeUsually 0 = standard
AA5Authoritative AnswerShown if reply is from the domain’s own DNS
TC6Truncated MessageResponse too large for UDP
RD7Recursion DesiredClient requests recursion
RA8Recursion AvailableServer supports recursion
RCODE12–15Response Code0 = No Error, 3 = NXDOMAIN

Example from dig:

;; flags: qr rd ra; status: NOERROR

Meaning:

  • qr: this is a response
  • rd: recursion desired
  • ra: recursion available
  • NOERROR: successful query

📦 Encapsulation in DNS

Encapsulation means wrapping one protocol’s data inside another as it moves through network layers.

Layer-by-Layer Breakdown

LayerProtocolEncapsulated DataExample
ApplicationDNSDNS Query/Response“What is IP of www.example.com?”
TransportUDP or TCPDNS MessageUDP Port 53
NetworkIPUDP SegmentSource: 192.168.1.2 → Dest: 8.8.8.8
Data LinkEthernetIP PacketMAC to MAC transfer

Visual Stack:

+-----------------------------+
| DNS Message (Header + Data) |
+-----------------------------+
| UDP Header (Port 53)        |
+-----------------------------+
| IP Header                   |
+-----------------------------+
| Ethernet Frame              |
+-----------------------------+

Most queries use UDP port 53, while TCP port 53 is used for large responses (like DNSSEC or zone transfers).


🧾 Dig Diagnostic Data (Not Header)

When you run dig, the first two lines are diagnostic, not part of the DNS message.

; <<>> DiG 9.18.1-1ubuntu1.3-Ubuntu <<>> www.example.com
;; global options: +cmd
LineSourcePart of DNS Message?
; <<>> DiG ... <<>>dig program banner❌ No
;; global options:Local configuration❌ No
;; ->>HEADER<<- ...Actual DNS message header✅ Yes

❓ Question Section Data

The Question Section specifies what the client is asking for.

FieldDescriptionExample
QNAMEDomain name requestedwww.example.com
QTYPERecord typeA (IPv4 address)
QCLASSUsually IN (Internet)IN

Example from dig:

;; QUESTION SECTION:
;www.example.com.          IN      A

This means:
“The client is asking for the IPv4 address (A record) of www.example.com.”


📘 Resource Records (RRs)

A Resource Record is the building block of DNS data — it contains a single piece of information about a domain.

Structure of a Resource Record

FieldDescriptionExample
NAMEThe domain namewww.example.com.
TYPEType of record (A, MX, NS, etc.)A
CLASSUsually IN (Internet)IN
TTLTime to Live (cache duration)3600
RDATAThe actual data (depends on type)93.184.216.34

Example

NAMETYPECLASSTTLRDATA
www.example.comAIN360093.184.216.34

Sections Containing RRs:

  1. Answer Section – Direct answers.
  2. Authority Section – Authoritative servers.
  3. Additional Section – Supporting data like IPs of NS servers.

💡 In short:
A Resource Record is a fact about a domain — and every DNS answer you receive is made up of one or more RRs.


🧭 Summary

ConceptPurpose
DNS LookupConverts domain names to IP addresses
Dig ToolDisplays DNS message details
HeaderMetadata and flags
Question SectionThe query being asked
Answer SectionThe actual result
Authority SectionReferences to authoritative servers
Additional SectionHelpful extra data (e.g., NS IPs)
Resource RecordsCore data units of DNS
EncapsulationHow DNS travels across network layers

✨ Final Thought

Next time you run dig www.example.com, you’re not just seeing text — you’re watching a complete, multi-layered exchange between your computer and the world’s DNS infrastructure.
Understanding these sections gives you the power to troubleshoot, teach, or secure networks with confidence.