📛 DNS
DNS (Domain Name System) is a distributed naming system for digital resources connected over public or private network.
The most visible feature of it is translating human-readable domain names like
www.example.comto machine-friendly IPs like240.95.41.196.
DNS zone is a portion of the DNS namespace that is managed by a single organization or administrator. It is a subtree of the DNS namespace.
Zone is usually a single domain like
example.com, but not always.
Each DNS zone is described by a zone file. Zone file is a collection of resource records that define translations between domain names and IP addresses. Usually software developers only need to work with the zone files of DNS zones.
$ORIGIN example.com.
$TTL 1h
example.com. IN A 192.0.2.1
www IN CNAME example.com.
wwwtest IN CNAME www
example.com. IN MX 10 mail.example.com.
mail IN A 192.0.2.3
Common record types:
- SOA: DNS zone authority definition, start of authority. Name of the authoritative primary name server for the zone and the email address of someone responsible for management of the name server. SOA is the only required record in a zone file.
- A: Domain name to IPv4 address. Some DNS providers allow non-IP targets for this record type e.g. Route53 allows Amazon endpoint names.
- AAAA: Domain name to IPv6 address.
- CNAME: Domain name to domain name, "canonical" domain name.
- MX: SMTP email service exchangers for the given domain name.
- NS: Authoritative name servers for this DNS database. Delegates handling of this DNS zone to the given name servers.
- PTR: Pointer to a domain name. Unlike CNAME, DNS processing stops and just the domain name is returned. Used to implement reverse DNS lookup service.
- SRV: Service name and protocol to domain name and port.
- TXT: Domain name to arbitrary text translation. Usually used for domain ownership validation for 3rd party services.
DNS name server is a server that stores and distributes DNS record data. Authoritative name servers are the source of the records while cache name servers are just distributors of the records.
Registrar vs Registry
Domain registrar is a service that sells domain names.
Domain registry is a big lookup table of nameserver (NS) records for a particular top-level domain (TLD) like .com.
When you buy a domain for a certain DNS zone, the domain registrar provides the names of authoritative name servers to the domain registry of the top-level domain containing the zone.
Root name server is a table of addresses to domain registries.
"Where is www.example.com?"
-> root name server
=> "I know this guy who knows a lot about .com at this IP, try that."
"Where is www.example.com?"
-> TLD name server (domain registry)
=> "Well this IP can help you with that. Lots of example stuff over there"
"Where is www.example.com?"
-> Name server
=> "OH www, I know the guy, just over at this IP."