Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 37 ยท Protocol Analysis

UDP and DNS

Read UDP datagrams and DNS messages in Wireshark: the 8-byte UDP header, query and response structure, record types, response codes, TCP fallback and DNS filters.

UDP is the simple transport: no connection, no retransmission, no ordering, just an 8-byte header on top of IP. It is used for DNS, DHCP, NTP, VoIP media, video, QUIC (HTTP/3) and games, where speed matters more than perfect delivery, or where the application adds its own reliability. DNS is the best protocol to practice reading on top of UDP, because every network problem eventually involves a name lookup.

The UDP header

Field Filter Size
Source port udp.srcport 2 bytes
Destination port udp.dstport 2 bytes
Length udp.length 2 bytes (header + data)
Checksum udp.checksum 2 bytes (optional in IPv4, mandatory in IPv6)

That is all. Because there is no handshake and no acknowledgment, you will not see connection setup; you see requests and responses, and it is up to the application (or you) to match them. When a UDP packet reaches a closed port, the host replies with ICMP "port unreachable" (type 3, code 3), which Wireshark displays and which is how you diagnose "no service listening".

Wireshark still groups UDP packets into conversations by the four-tuple (addresses and ports), and udp.stream numbers them.

DNS in one paragraph

The Domain Name System turns names into data: addresses, mail servers, text records and more. A client (the stub resolver) sends a query to a recursive resolver (your router, ISP or a public resolver), which finds the answer by asking authoritative servers and caches it. In a capture on a client you normally see only the first leg: query to the resolver and its response, on UDP port 53. DNS moves to TCP port 53 when the response does not fit (truncated, with the TC flag) or for zone transfers, and uses TLS or HTTPS (DoT port 853, DoH port 443) when encrypted, in which case the names are not visible in a plain capture.

DNS message structure

A DNS message has a 12-byte header, then four sections:

flowchart TB
    H["Header: ID, flags, counts"] --> Q["Question: name, type, class"]
    Q --> A["Answer records"]
    A --> AU["Authority records"]
    AU --> AD["Additional records"]

Every DNS message has the same layout; queries usually have only the question section filled in.

Important header fields: the transaction ID (matches a response to its query, dns.id), the QR flag (0 query, 1 response), RD/RA (recursion desired/available), AA (authoritative answer), TC (truncated) and the response code dns.flags.rcode:

rcode Name Meaning
0 NOERROR Success (an empty answer with NOERROR means "name exists, no such record type")
2 SERVFAIL The resolver could not get an answer (broken DNSSEC, unreachable servers)
3 NXDOMAIN The name does not exist
5 REFUSED The server refuses to answer you

Common record types (dns.qry.type): A (1, IPv4 address), NS (2), CNAME (5, alias), SOA (6), PTR (12, reverse lookup), MX (15, mail), TXT (16), AAAA (28, IPv6), SRV (33), HTTPS (65) and CAA (257). Browsers often ask for A and AAAA (and HTTPS) at the same time.

In the Packet List, Wireshark shows Standard query 0x1a2b A example.org and Standard query response 0x1a2b A example.org A 192.0.2.80. It also links them: select a response and look for [Request In: 5] and [Time: 0.012 seconds]; filter on dns.time > 0.5 to find slow answers.

Build and parse a DNS message

The stand-in builds a DNS query and a response (with name compression, where a two-byte pointer 0xc00c refers back to the name in the question) and parses them. Names are sequences of length-prefixed labels ending with a zero byte. Only the standard library is used and nothing is sent anywhere. The addresses are from the documentation range.

Python Build and decode a DNS query and response (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Spotting DNS problems

Match each query to its response by transaction ID and look at the time and the code.

Python Summarize DNS lookups: slow, failed, unanswered (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Useful DNS and UDP filters

TEXT
dns                                      all DNS
dns.flags.response == 0                  queries only
dns.qry.name contains "example"          names containing a string
dns.flags.rcode != 0                     errors
dns.flags.rcode == 3                     NXDOMAIN
dns.time > 0.5                           slow responses
dns.qry.type == 28                       AAAA lookups
dns.flags.truncated == 1                 truncated, expect a TCP retry
udp.port == 53 and not dns               port 53 traffic that does not decode as DNS (odd)
icmp.type == 3 and icmp.code == 3        UDP port unreachable

A resolver that answers slowly causes slow page loads that look like "the website is slow". A client that sends repeated queries without answers points at a firewall blocking UDP 53, a wrong resolver address, or a dead resolver; a machine that asks for many names that do not exist (NXDOMAIN) may be misconfigured or infected, which we use in the security chapter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which transport and port does a standard DNS query normally use?

    DNS uses UDP port 53, falling back to TCP port 53 for large responses and zone transfers.
  2. 2. What does rcode 3 (NXDOMAIN) mean?

    NXDOMAIN means the domain name does not exist, which is typical of typos and blocked names.
  3. 3. How does Wireshark match a DNS response to its query?

    The 16-bit transaction ID is copied from the query into the response.
  4. 4. You see ICMP type 3 code 3 after a UDP packet. What does it tell you?

    Port unreachable is the UDP equivalent of a refused connection.

Summary

  • UDP has a tiny 8-byte header and no connection state; request/response matching is up to the application.
  • DNS messages have a header, question, answer, authority and additional sections; names are labels, often compressed with pointers.
  • rcodes (NOERROR, SERVFAIL, NXDOMAIN, REFUSED), the query type and dns.time explain most name-resolution problems.
  • Large DNS responses move to TCP; encrypted DNS (DoT, DoH) hides names from a plain capture.
  • ICMP port unreachable is the sign of a closed UDP port.

Next: HTTP and the TLS Handshake