A Deep Dive into how the DNS Protocol Works

Updated: Oct 19, 2026

 
pkg search tcpdump
pkg install tcpdump-4.99.6

pkg search socat
pkg install socat-1.8.1.3

dig -4 @127.0.0.1 -t soa google.com

dig -4 +trace -t soa google.com


man dig
man tcpdump
man socat

 

DNS Payload

 

Query in HEX

 2f 36 01 00 00 01 00 00 00 00 00 00 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 00 06 00 01

Header
 ID      | 2f 36 | |00101111 00110110| 12086
 OPFLAGS | 01 00 | | 0| 0000 | 0| 0| 1| 0|000| 0000|
                   |QR|OPCODE|AA|TC|RD|RA| Z |RCODE|
 QCOUNT  | 00 01 | |00000000 00000001|
 ACOUNT  | 00 00 | |00000000 00000000|
 NSCOUNT | 00 00 | |00000000 00000000|
 ARCOUNT | 00 00 | |00000000 00000000|

Question Section

 QNAME   | 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 | 
         |  6  g  o  o  g  l  e  3  c  o  m  0 | 
 QTYPE   | 00 06 | |00000000 00000110| | SOA
 QCLASS  | 00 01 | |00000000 00000001| | IN 

Operational Codes (OPCODE) 4 bits
 0000 Standard query
 0001 Inverse query(Deprecated)
 0010 Status
 0100 Notify
 0101 Update

Response Codes (RCODE) Orignially 4 bits (Extended Response codes bled in to Z(padding) bits)
 0000  NoError   No Error
 0001  FormErr   Format Error
 0010  ServFail  Server Failure
 0011  NXDomain  Non-Existent Domain
 0100  NotImp    Not Implemented
 0101  Refused   Query Refused
 0110  YXDomain  Name Exists when it should not
 0111  YXRRSet   RR Set Exists when it should not
 1000  NXRRSet   RR Set that should exist does not
 1001  NotAuth   Server Not Authoritative for zone
 1010  NotZone   Name not contained in zone

Extended response codes
 1 0000  BADSIG    TSIG Signature Failure
 1 0001  BADKEY    Key not recognized
 1 0010  BADTIME   Signature out of time window
 1 0011  BADMODE   Bad TKEY Mode
 1 0100  BADNAME   Duplicate key name
 1 0101  BADALG    Algorithm not supported


Common Query Types in Hex
 A (Address Record (IPv4)) - 00 01
 NS (Name Server Record) - 00 02
 CNAME (Canonical Name Record)- 00 05
 SOA (Start Of Authority Record)- 00 06
 PTR (Pointer Record) - 00 0c
 MX (Mail eXchange Record) - 00 0f
 TXT (Text Record) - 00 10
 AAAA (IPv6 Address Record) - 00 1c
 SRV (Service Record) - 00 21
 HINFO (Host Information Record) - 00 0d
 RP (Responsible Party Record) - 00 11
 LOC (Location Record) - 00 1d
 APL (Address Prefix List Record) - 00 2a
 SVCB (Service Binding Record)- 00 40
 HTTPS (Service Binding Record for HTTP) - 00 41
 SPF (Sender Policy Framework Record (Obsolete use TXT)) - 00 63
 AXFR (Zone Transfer All) - 00 fc
 IXFR (Zone Transfer Incremental) - 00 fb
 CAA (Certificate Authority Authorization Record) - 01 01





 echo -n "2f360100000100000000000006676f6f676c6503636f6d0000060001" | xxd -r -p | base64

 LzYBAAABAAAAAAAABmdvb2dsZQNjb20AAAYAAQ==

 echo -n "LzYBAAABAAAAAAAABmdvb2dsZQNjb20AAAYAAQ==" | base64 --decode | socat -x - UDP:127.0.0.1:53 | hexdump -e '1/1 " %02X"'

 dig @127.0.0.1 +qid=12086 -t soa google.com

 tcpdump -nn -i ena0 udp port 53 -w dns1.pcap
 tcpdump -nn -r dns1.pcap
 
HexBinaryCharDescription
0000000000NULNull
0100000001SOHStart of Heading
0200000010STXStart of Text
0300000011ETXEnd of Text
0400000100EOTEnd of Transmission
0500000101ENQEnquiry
0600000110ACKAcknowledge
0700000111BELBell
0800001000BSBackspace
0900001001HTHorizontal Tab
0A00001010LFNL Line Feed, New Line
0B00001011VTVertical Tab
0C00001100FFNP Form Feed, New Page
0D00001101CRCarriage Return
0E00001110SOShift Out
0F00001111SIShift In
1000010000DLEData Link Escape
1100010001DC1Device Control 1
1200010010DC2Device Control 2
1300010011DC3Device Control 3
1400010100DC4Device Control 4
1500010101NAKNegative Acknowledge
1600010110SYNSynchronous Idle
1700010111ETBEnd of Transmission Block
1800011000CANCancel
1900011001EMEnd of Medium
1A00011010SUBSubstitute
1B00011011ESCEscape
1C00011100FSFile Separator
1D00011101GSGroup Separator
1E00011110RSRecord Separator
1F00011111USUnit Separator
2000100000(Space)Space
2100100001!Exclamation Mark
2200100010"Double Quote
2300100011#Hash or Number
2400100100$Dollar Sign
2500101001%Percent
2600100110&Ampersand
2700100111'Single Quote
2800101000(Left Parenthesis
2900101001)Right Parenthesis
2A00101010*Asterisk
2B00101011+Plus
2C00101100,Comma
2D00101101-Hyphen
2E00101110.Period
2F00101111/Slash
30001100000Digit 0
31001100011Digit 1
32001100102Digit 2
33001100113Digit 3
34001101004Digit 4
35001101015Digit 5
36001101106Digit 6
37001101117Digit 7
38001110008Digit 8
39001110019Digit 9
3A00111010:Colon
3B00111011;Semicolon
3C00111100<Less Than
3D00111101=Equals
3E00111110>Greater Than
3F00111111?Question Mark
4001000000@At Sign
4101000001AUppercase A
4201000010BUppercase B
4301000011CUppercase C
4401000100DUppercase D
4501000101EUppercase E
4601000110FUppercase F
4701000111GUppercase G
4801001000HUppercase H
4901001001IUppercase I
4A01001010JUppercase J
4B01001011KUppercase K
4C01001100LUppercase L
4D01001101MUppercase M
4E01001110NUppercase N
4F01001111OUppercase O
5001010000PUppercase P
5101010001QUppercase Q
5201010010RUppercase R
5301010011SUppercase S
5401010100TUppercase T
5501010101UUppercase U
5601010110VUppercase V
5701010111WUppercase W
5801011000XUppercase X
5901011001YUppercase Y
5A01011010ZUppercase Z
5B01011011[Left Square Bracket
5C01011100\Backslash
5D01011101]Right Square Bracket
5E01011110^Caret
5F01011111_Underscore
6001100000`Backtick/Grave Accent
6101100001aLowercase a
6201100010bLowercase b
6301100011cLowercase c
6401100100dLowercase d
6501100101eLowercase e
6601100110fLowercase f
6701100111gLowercase g
6801101000hLowercase h
6901101001iLowercase i
6A01101010jLowercase j
6B01101011kLowercase k
6C01101100lLowercase l
6D01101101mLowercase m
6E01101110nLowercase n
6F01101111oLowercase o
7001110000pLowercase p
7101110001qLowercase q
7201110010rLowercase r
7301110011sLowercase s
7401110100tLowercase t
7501110101uLowercase u
7601110110vLowercase v
7701110111wLowercase w
7801111000xLowercase x
7901111001yLowercase y
7A01111010zLowercase z
7B01111011{Left Curly Brace
7C01111100|Pipe/Vertical Bar
7D01111101}Right Curly Brace
7E01111110~Tilde
7F01111111DELDelete