Sub topic 4
Resource records: A, AAAA, CNAME, MX, NS, TXT and SOA
This chapter assumes you know what a domain name hierarchy is, what a zone is, and how IPv4 and IPv6 addresses look. You should also be comfortable running commands in a terminal.
What a resource record is
A DNS zone is a collection of resource records (RRs). Each record has the same five fields: a name, a TTL, a class, a type, and the data. The class is almost always IN (Internet). The type decides what the data means.
The common record types
| Type | Data it holds | Typical use |
|---|---|---|
| A | An IPv4 address | Point a name at a server |
| AAAA | An IPv6 address | Same, over IPv6 |
| CNAME | Another name | Make one name an alias of another |
| MX | A priority number and a mail server name | Say where email for the domain goes |
| NS | A name server name | Say which servers are authoritative for a zone |
| TXT | Free-form text | SPF, domain verification, DKIM keys |
| SOA | Zone administration values | One per zone, describes the zone itself |
Reading a zone file
This minimal zone uses addresses reserved for documentation.
$ORIGIN example.com.
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2026112701 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
300 ) ; negative caching TTL
IN NS ns1.example.com.
IN NS ns2.example.com.
IN MX 10 mail.example.com.
IN A 192.0.2.10
IN AAAA 2001:db8::10
www IN CNAME example.com.
mail IN A 192.0.2.25
ns1 IN A 192.0.2.53
ns2 IN A 192.0.2.54The @ stands for the zone origin, example.com.. A line that starts with whitespace reuses the previous name, so the NS, MX, A and AAAA lines all belong to example.com.. The trailing dot marks a fully qualified name. Without it, the origin is appended, so ns1.example.com would become ns1.example.com.example.com.. This is a very common mistake.
How each type behaves
A and AAAA. A name can have several of each. Resolvers return them all, and clients choose which to try. The Python call below returns both families when both exist.
import socket
results = socket.getaddrinfo("example.com", 443, type=socket.SOCK_STREAM)
for family, socktype, proto, canonname, sockaddr in results:
print(family.name, sockaddr[0])CNAME. A CNAME says "this name is an alias; look up the target instead." A name that has a CNAME cannot have any other record type. For that reason you cannot put a CNAME at the zone apex (example.com.), because the apex must hold SOA and NS records.
MX. The number is a preference. Lower values are tried first, so 10 is tried before 20. The target must be a name with an A or AAAA record, not a CNAME.
NS. NS records at the apex list the zone's authoritative servers. NS records for a child name delegate that part of the namespace to other servers.
TXT. TXT records carry text that other systems read. Email authentication and ownership checks rely on them.
SOA. The serial number should increase with every change, because secondary servers compare serials to decide whether to copy the zone. Refresh, retry and expire control that copying. The last value is the negative caching TTL, which is how long resolvers remember that a name does not exist.
Querying records with dig
dig example.com A
dig +short example.com AAAA
dig +noall +answer example.com MX+short prints only the data. +noall +answer prints only the answer section, with name, TTL, class, type and data on each line.
Exercise
Why can't you add a CNAME record for example.com. itself in the zone above?
Show answer
A name with a CNAME cannot hold any other record types, but the apex must hold SOA and NS records. The two rules conflict, so the apex needs A and AAAA records instead.
Exercise
A zone has MX 10 mail1.example.com. and MX 20 mail2.example.com. Which server does a sender try first, and why?
Show answer
mail1.example.com. is tried first. MX values are preferences and the lowest number has the highest priority. mail2 is the fallback.