Sub topic 10
Pointing your domain at your host
You have a registered domain and a place to run a website. This chapter covers the step that joins them: publishing DNS data that sends visitors to your host.
This chapter assumes you know what the DNS record types A, AAAA, CNAME, MX and NS do. It also assumes you understand TTL and caching, and that the registrar and the DNS provider are separate roles. You should be able to run dig from a terminal.
Two ways to connect a domain
Your host will ask you to do one of two things.
- Change the nameservers at your registrar so the host's DNS servers become authoritative for your zone. The host then manages every record.
- Add records (an A record, a CNAME, or both) in the DNS zone you already use. The nameservers stay where they are.
| Approach | What changes | Good when | Risk |
|---|---|---|---|
| Delegate to the host's nameservers | NS records at the registry | The host manages DNS well and you have no other services on the domain | Your existing records (mail, verification TXT) are lost unless you recreate them |
| Add records at the current DNS provider | A, AAAA or CNAME records in your zone | You use separate providers for DNS, mail and hosting | You must keep the records in sync with what the host expects |
Records are the more flexible option. A domain has one set of nameservers but can point to many services: a website on one host, mail on another, and a documentation site on a third.
Choosing between A and CNAME
The host gives you either an IP address or a hostname. That choice decides the record type.
- An IP address (typical for a VPS or dedicated server) needs an A record, and an AAAA record if it also gives you an IPv6 address.
- A hostname (typical for platforms and CDNs) needs a CNAME. The platform can then change its IP addresses without asking you to update anything.
The apex problem
The apex (also called the root or bare domain) is example.com itself. Its record set already contains SOA and NS records. A CNAME cannot share a name with any other record type, so a standard CNAME at the apex is not allowed. It would conflict with the SOA and NS records, and with any MX or TXT records you add.
You have three options:
- Use the A and AAAA addresses the host publishes, if it offers fixed ones.
- Use your DNS provider's alias feature. It may be called ALIAS, ANAME or CNAME flattening. The provider resolves the target itself and answers with A and AAAA records. This is a provider feature, not a standard record type, so the name and behavior vary.
- Point only
wwwat the host with a CNAME, and have the apex redirect towwwat the registrar or DNS provider.
A zone that points to a VPS and a platform
The records below send the apex to a VPS and app to a platform hostname. The www name aliases the apex.
$ORIGIN example.com.
$TTL 300
@ IN A 192.0.2.10
@ IN AAAA 2001:db8::10
www IN CNAME example.com.
app IN CNAME example-app.hosting-platform.example.
@ IN MX 10 mail.example.com.
mail IN A 192.0.2.25Two details cause many mistakes. The trailing dot on hosting-platform.example. marks a fully qualified name. Without it, most zone files and some provider forms append your own domain, which gives example-app.hosting-platform.example.example.com. Also, the $TTL 300 line sets a short TTL, which is explained next.
Preparing for the change
Do this before you edit anything, especially on a domain that already serves real traffic.
- Lower the TTL. Resolvers cache the old record for as long as its previous TTL. If the current TTL is 86400 seconds, lower it to 300 at least one full old-TTL period before the change.
- Record the current state. Save the output of
dig example.com ANY +noall +answer, or export the zone. Many providers answer ANY queries minimally, so querying types one at a time is more reliable. - Get the new host ready first. Deploy the site and test it with the host's temporary URL or by sending a request directly to its IP.
- List every service on the domain. Mail (MX), SPF and DKIM TXT records, and site verification records must survive the move.
Making the change
Option 1: edit records
- Open the zone at your current DNS provider.
- Remove or edit the old A, AAAA or CNAME records for the name you are pointing. Do not leave an old AAAA record behind when the new host has no IPv6. Clients that prefer IPv6 will keep reaching the old server.
- Add the records the host gave you.
- Save. Most providers publish the change to their authoritative servers within seconds.
Option 2: change nameservers
- Add the domain at the host and note the nameserver names it assigns.
- Recreate all other records in the host's zone.
- At the registrar, replace the NS values and save. The registrar passes the change to the registry, which updates the delegation in the TLD zone.
- Wait. The parent zone's NS records have their own TTL, often 24 to 48 hours for TLD servers, so this change takes longer to spread than a record edit.
If the domain has DNSSEC enabled, remove the DS record at the registrar before switching nameservers, unless the new provider can take over signing. Otherwise validating resolvers treat the domain as bogus and return errors.
Verifying the result
Check the authoritative server first, then public resolvers. This tells you whether a problem is in your zone or only in caches.
# 1. Find the authoritative nameservers
dig example.com NS +short
# 2. Ask one of them directly (no caching involved)
dig @ns1.example.com example.com A +short
# 3. Ask public resolvers and compare
dig @1.1.1.1 example.com A +short
dig @8.8.8.8 example.com A +short
# 4. Follow a CNAME chain
dig www.example.com +noall +answerIf step 2 shows the new value and steps 3 still show the old one, your zone is correct and you are waiting for caches. The remaining TTL appears in the second column of the answer and counts down each time you query the same resolver.
You can also check what a program on your machine sees. This uses the operating system's resolver, so it includes any local caching and the hosts file.
import socket
EXPECTED = {"192.0.2.10"}
def ipv4_addresses(name):
infos = socket.getaddrinfo(
name, 443, family=socket.AF_INET, type=socket.SOCK_STREAM
)
return {sockaddr[0] for _, _, _, _, sockaddr in infos}
for name in ("example.com", "www.example.com"):
try:
found = ipv4_addresses(name)
except socket.gaierror as err:
print(f"{name}: lookup failed ({err})")
continue
status = "OK" if found == EXPECTED else "UNEXPECTED"
print(f"{name}: {sorted(found)} {status}")Replace the expected address with your own. For a name behind a CDN or platform, the set of addresses changes, so check the CNAME target with dig instead.
Common errors and their causes
| Symptom | Likely cause | Fix |
|---|---|---|
| Host's error page, or 404, on your domain | DNS is correct but the host does not know your domain name | Add the domain in the host's dashboard so it routes the `Host` header |
| Old site still appears for some visitors | Resolver caches or an old AAAA record | Check with `dig @resolver`, remove stale records, wait for the old TTL |
| `www` works but the bare domain does not (or the reverse) | Only one name has a record | Add the missing record, or add a redirect |
| CNAME rejected by the DNS provider | A CNAME at the apex, or another record on the same name | Use A/AAAA, an ALIAS record, or move the CNAME to `www` |
| NXDOMAIN for the new name | Record added in the wrong zone, or the name was typed with the domain repeated | Check the name in the zone, and use the trailing dot if the form allows it |
| Mail stopped after the move | MX records not copied to the new zone | Recreate MX and mail-related TXT records |
| Browser certificate warning | The host has not issued a certificate for the name yet | Wait for provisioning, or see the HTTPS chapter |
| Works at home, fails elsewhere | Local cache, hosts file, or ISP resolver | Test from another network and with `dig @1.1.1.1` |
Avoiding downtime on a live site
For a domain that is already in use, treat the change as a short overlap, not a cutover.
- Lower the TTL and wait one old-TTL period.
- Make sure the old and new servers both serve the same content, even if only temporarily.
- Change the record. Visitors reach either server depending on cache age, and both work.
- Keep the old server running for at least the old TTL, and longer if you can see traffic still arriving in its logs.
- Raise the TTL again to something like 3600 once things are stable. A very short TTL increases query load and slightly slows first visits.
Exercise
You add CNAME @ -> myapp.hosting-platform.example. at your DNS provider and the form rejects it. Why, and what are two ways to point the bare domain at the platform?
Show answer
The apex already holds SOA and NS records (and likely MX and TXT), and a CNAME cannot coexist with other record types on the same name. You can use the provider's ALIAS, ANAME or CNAME-flattening feature, which answers with the platform's A and AAAA records, or you can point www at the platform with a CNAME and redirect the bare domain to www. If the platform publishes fixed IP addresses, plain A and AAAA records also work.
Exercise
After changing an A record, dig @ns1.example.com example.com A +short returns the new IP, but dig @1.1.1.1 example.com A +short still returns the old one. Is something wrong with your zone? What do you check next, and what do you do?
Show answer
The zone is correct, because the authoritative server returns the new value. The public resolver is serving a cached answer. Run dig @1.1.1.1 example.com A without +short and read the TTL in the answer. That number is the seconds left until the cache entry expires. Wait that long and query again. You do not need to change anything unless the authoritative answer is also wrong.
Exercise
You move a domain to the new host's nameservers, and two days later a colleague says email to the domain is bouncing. What most likely happened, and how would you confirm it?
Show answer
The new zone does not contain the MX records (and likely not the SPF, DKIM and verification TXT records), because changing nameservers replaces the whole zone. Confirm with dig example.com MX +short against the new nameservers. If it returns nothing, recreate the old MX records in the new zone, using the values you saved before the change.