networking, updated

DNS

The Domain Name System turns names into addresses and much more (mail servers, service records, verification). Almost every connection starts with a DNS lookup, which makes it a goldmine for detection and a favourite channel for attackers.

OSI layer
7 Application
Carried in
UDP (TCP for large answers and zone transfers)
Ports
53/udp, 53/tcp, 853/tcp (DoT), 443/tcp (DoH), 5353/udp (mDNS)
Specs
RFC 1034, RFC 1035, RFC 6891, RFC 4033, RFC 8484
Wireshark filter
dns
Encrypted
no

Packet structure

DNS message12 bytes + variable

Select a field to see what it does.

RFC 1035. A 12-byte header followed by four sections. The same format is used for queries and responses, over UDP, TCP (2-byte length prefix), DoT and DoH.

Over TCP the message is prefixed with a 2-byte length. Classic UDP answers are limited to 512 bytes; EDNS0 (an OPT record in the additional section) allows bigger ones, typically 1232 bytes today.

How it works

sequenceDiagram
    participant C as Client (stub)
    participant R as Recursive resolver
    participant Root as Root server
    participant TLD as .com server
    participant A as example.com server
    C->>R: A www.example.com? (RD=1)
    R->>Root: www.example.com?
    Root-->>R: referral to .com NS
    R->>TLD: www.example.com?
    TLD-->>R: referral to example.com NS
    R->>A: www.example.com?
    A-->>R: A 93.184.215.14 (AA=1, TTL 3600)
    R-->>C: A 93.184.215.14 (RA=1)

The resolver caches each answer for its TTL, so most lookups are answered from cache. Negative answers (NXDOMAIN) are cached too.

Common record types: A, AAAA, CNAME, MX, NS, TXT, PTR, SOA, SRV (Active Directory uses _ldap._tcp.dc._msdcs.<domain>), CAA, HTTPS/SVCB. Click the Question field above for the type numbers.

In Wireshark

FilterShows
dnsAll DNS (UDP and TCP 53)
dns.flags.response == 0Queries
dns.qry.name contains "example"Lookups for a name
dns.flags.rcode == 3NXDOMAIN (typos, DGA malware, blocked domains)
dns.flags.rcode == 2SERVFAIL
dns.qry.type == 16TXT queries (verification, tunnels)
dns.qry.type == 252Zone transfer attempts (AXFR)
dns.qry.type == 255ANY queries (amplification)
dns.flags.truncated == 1Truncated answers, retried over TCP
len(dns.qry.name) > 50Very long names (tunnelling, encoded data)
dns && !(ip.dst == 10.0.0.53 or ip.src == 10.0.0.53)DNS that bypasses your resolver
dns.resp.ttl < 60Very short TTLs (fast flux, load balancing)

Statistics › DNS gives a quick overview of query types and response codes.

What normal looks like: clients ask the internal resolver only; query and answer pairs with matching IDs; mostly A, AAAA, HTTPS, PTR and SRV; few NXDOMAINs.

Security notes

References

§ home
~/knubertus/home/
1,1 Top