Sub topic 10
Pointing your domain at your host
This chapter assumes you know what A, AAAA, CNAME, MX and NS records are. It also assumes you understand TTL and caching, and the difference between a registrar and a host. Here you will connect a registered domain to a place where your site runs.
Two ways to connect
Your host gives you one of two things to use:
- Nameservers. You change the domain's NS delegation at the registrar so the host's name servers answer for the whole zone. The host then manages every record.
- Records. You keep your current DNS provider and add records that point at the host: an IP address for A and AAAA, or a hostname for CNAME.
Pick one. Delegation moves control of all DNS, including mail records. Editing records changes only what you edit.
Apex versus www
The apex (example.com) and the subdomain www.example.com need different treatment.
- A CNAME cannot share a name with other records. The apex always has SOA and NS records, so a standard CNAME there is invalid.
- For the apex, use A and AAAA records with the host's addresses. Some providers offer ALIAS, ANAME or CNAME flattening, which resolves a hostname for you and serves it as address records.
- For
www, a CNAME to a hostname the host gives you is usually best, because the host can change its IPs without you editing anything.
This zone fragment uses documentation addresses:
@ IN A 192.0.2.10
@ IN AAAA 2001:db8::10
www IN CNAME example.com.Here www is an alias of the apex, so both names reach the same server. If your host gives you a target such as sites.host.example., point www at that name instead.
A safe change sequence
- Lower the TTL on the records you will change, for example to 300 seconds. Do this at least one old-TTL period before the change.
- Get the host's target values (IPs or hostname) from its dashboard.
- If delegating, recreate every existing record at the new provider first, especially MX and TXT.
- Make the change.
- Verify, then raise the TTL again once things work.
Verifying the change
Ask the authoritative server first, because it has no cache to confuse you. Then ask public resolvers.
dig example.com NS +short
dig @ns1.example.com example.com A +short
dig @1.1.1.1 www.example.com CNAME +short
dig @1.1.1.1 example.com A +shortIf the authoritative server is right but a public resolver still shows the old value, the old answer is cached and will expire after its TTL. You can also confirm what a program sees:
import socket
for family, _, _, _, sockaddr in socket.getaddrinfo("example.com", 443, type=socket.SOCK_STREAM):
print(family.name, sockaddr[0])Common errors
| Symptom | Likely cause |
|---|---|
| Old site appears on some networks | Resolver cache still holds the old record |
| Site works over IPv4 only for some users | A stale AAAA record points to the old server |
| Provider rejects the CNAME at the apex | CNAME conflicts with SOA and NS; use A/AAAA or ALIAS |
| Records changed but nothing happens | The records were edited at a provider that is not the delegated one |
| Host shows "domain not verified" | Missing TXT or CNAME verification record, or a typo in it |
The fourth row is the most common mistake. Run dig example.com NS +short to see which provider the registrar delegates to. Only that provider's records count.
Exercise
Your registrar delegates example.com to Provider A, but you added an A record for the apex in Provider B's dashboard. Why does the site not change, and how do you confirm it?
Show answer
Only the name servers listed in the NS delegation are authoritative. Provider B's zone is never consulted. Run dig example.com NS +short to see the delegated servers, then either add the record at Provider A or change the NS records at the registrar to Provider B.