Which DNS record types should you know, and why does DNS use UDP port 53?
MediumConceptDNS, HTTP & HTTPS
Answer
DNS stores several kinds of records for a name. It normally carries queries over UDP port 53, because a typical query and its answer each fit in one small packet, so no connection setup is needed.
- Record types: A (name to IPv4 address), AAAA (name to IPv6 address), CNAME (alias for another name), MX (mail server for a domain), NS (authoritative name servers), TXT (text, used for domain verification) and PTR (address to name, for reverse lookups).
- Why UDP: one request and one reply with no handshake keep lookups fast; if a reply is lost, the resolver simply asks again.
- When TCP port 53: for zone transfers (copying all of a domain's records from a primary to a secondary server) and when an answer is too large for UDP. The server then sets the truncated (TC) flag and the client retries over TCP.
Example: A dig query for mail servers:
$ dig example.com MX
example.com. 3600 IN MX 10 mail.example.com.
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
The MX record says that mail for example.com goes to mail.example.com, with preference 10, and the last line shows that the query used UDP port 53.