Moving a website to a new hosting provider is one of the most stressful jobs in IT, and almost all of the stress comes from DNS. Change the wrong thing, forget one record, or change the right thing at the wrong time, and your site or your email disappears for hours. Done properly, visitors never notice anything.
This guide explains DNS from the ground up, then gives you two complete, tested migration plans. You do not need to know anything about DNS to start. By the end you will understand what nameservers are, what each record type does, why changes seem to “take 48 hours”, and exactly what to do when you switch hosting providers.
1. How DNS works in two minutes
Computers find each other by numbers (IP addresses such as 203.0.113.10), but people remember names (example.com). DNS, the Domain Name System, is the phone book that translates names into numbers. It is also much more than that: it tells the world where your email goes, which services may send mail for you, and who is allowed to issue certificates for your domain.
When someone types www.example.com into a browser, this happens in a fraction of a second:
Browser -> Recursive resolver (your ISP, Google 8.8.8.8, Cloudflare 1.1.1.1)
|
| 1. "Who knows about .com?" -> Root servers
| 2. "Who knows about example.com?" -> .com servers (the registry)
| 3. "What is www.example.com?" -> example.com's own nameservers
v
Answer: 203.0.113.10 (cached for the record's TTL)
Three kinds of servers are involved:
- The recursive resolver does the legwork for you and remembers answers for a while. This memory (cache) is the reason DNS changes are not instant.
- The registry (for example the operator of
.com) knows which nameservers are responsible for each domain. - The authoritative nameservers hold the actual records of your domain. They are the final source of truth.
The key idea for everything below: your domain’s records live in one place, the authoritative nameservers, and the registry only stores a pointer to them.
2. Registrar, DNS host and web host: three different jobs
Most confusion comes from mixing up three roles. Often one company does all three, which hides the difference, until the day you want to change just one of them.
| Role | What it does | Examples of what you pay for |
|---|---|---|
| Registrar | Sells you the right to use the domain name and tells the registry which nameservers to use. | The yearly domain renewal |
| DNS host | Runs the authoritative nameservers where your records are stored and edited. | Usually free with the registrar or the web host |
| Web host | Runs the server that actually delivers your website (and sometimes your mailboxes). | Shared hosting, VPS, cloud server |
People use the word “moving” for three completely different operations:
- Transferring the domain to another registrar. This changes who you pay for the name. It does not move your website or your DNS records.
- Changing the nameservers. This changes which DNS host is in charge of your records.
- Changing the web host. This is usually just changing a couple of records (the IP address) so they point at the new server.
Moving to a new hosting provider only requires number 3. Number 2 is optional, and number 1 is almost never needed. Understanding this removes most of the risk.
3. Nameservers explained
A nameserver is a server that answers DNS questions about a domain. Every domain has at least two (for redundancy), written as names like ns1.example-dns.com and ns2.example-dns.com.
Two places mention your nameservers, and it is crucial to know the difference:
- At the registrar you set the “nameservers” for the domain. The registrar passes them to the registry (
.com,.net,.ma…). This is the delegation: the official statement “for this domain, ask these servers”. - Inside your DNS zone there are also
NSrecords listing the same servers.
The golden rule: the nameservers set at the registrar decide which DNS zone is “live”. If your domain uses the nameservers of Provider A, editing the records in Provider B’s panel changes nothing, no matter how correct they look. This is the number one reason people say “I changed the record but nothing happens”.
See which nameservers your domain really uses:
dig +short NS example.com
# Windows:
nslookup -type=NS example.com
Glue records (only when nameservers are inside the domain)
If you run your own nameservers under the domain itself, for example ns1.example.com for example.com, there is a chicken-and-egg problem: to find ns1.example.com you must first ask the nameserver at ns1.example.com. Glue records solve this: you register the IP addresses of those nameservers at the registrar so the registry can hand them out directly. You only need this if you operate your own DNS or use vanity nameservers.
4. The DNS records you will actually meet
A DNS zone is the list of all records of a domain. Here is an example zone, followed by what every line means:
example.com. 3600 IN A 203.0.113.10
example.com. 3600 IN AAAA 2001:db8::10
www.example.com. 3600 IN CNAME example.com.
example.com. 3600 IN MX 10 mail.example.com.
mail.example.com. 3600 IN A 203.0.113.25
example.com. 3600 IN TXT "v=spf1 mx -all"
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"
example.com. 3600 IN CAA 0 issue "letsencrypt.org"
example.com. 86400 IN NS ns1.example-dns.com.
example.com. 86400 IN NS ns2.example-dns.com.
| Type | Purpose | Changes when you switch web host? |
|---|---|---|
| A | Name to IPv4 address. This is the record that points your site at a server. | Yes, the main change |
| AAAA | Name to IPv6 address. | Yes. Update it or delete it. Forgetting it is a classic mistake. |
| CNAME | “This name is an alias of another name”. Cannot coexist with other records on the same name, so it is not allowed on the bare domain. | Only if it points to the old host’s name |
| MX | Which servers receive email for the domain, with a priority (lower number is tried first). | No, unless email also moves |
| TXT | Free text used for SPF, DKIM, DMARC and ownership verification (Google, Microsoft…). | No, but SPF may list the old host |
| NS | The authoritative nameservers. | Only if you change DNS host |
| SOA | Administrative data of the zone: primary server, serial number, timers. Created automatically. | No |
| CAA | Which certificate authorities may issue certificates for the domain. | No, but the new host’s CA must be allowed |
| SRV | Where a specific service lives (SIP, Microsoft Teams, some game servers). | Rarely |
| PTR | Reverse lookup, IP to name. Controlled by whoever owns the IP, not by your zone. | Only for mail servers: ask the new provider |
Two practical notes:
- Bare domain and www are different names.
example.comandwww.example.comeach need their own record (or the www can be a CNAME to the bare domain). A site that works on one and not the other almost always has this gap. - Some providers offer ALIAS / ANAME / “CNAME flattening” so you can point the bare domain at a hostname. It is a provider feature, not standard DNS, but very handy with CDNs and cloud platforms.
5. TTL and “propagation”: what really happens when you change a record
Every record has a TTL (time to live), a number of seconds that tells resolvers how long they may remember the answer before asking again. A TTL of 3600 means one hour.
Now the myth to drop: DNS changes do not “propagate” or get pushed anywhere. Nothing is sent around the world. What happens is much simpler: the moment you save the change, your authoritative nameservers answer with the new value. But everyone who asked before still has the old answer in their cache, and keeps using it until its timer runs out. Different resolvers asked at different moments, so their timers expire at different moments. That is the “propagation” you see: caches expiring one after another.
This gives you the one rule that makes migrations painless:
The worst case wait after changing a record is the record’s TTL as it was before you changed it. To make a change fast, you must lower the TTL before the change, and wait at least the old TTL for that low value to spread.
| Cache layer | How long it keeps old answers |
|---|---|
| Public and ISP resolvers | Up to the record’s TTL (some ISPs stretch short TTLs) |
| Your operating system | Minutes |
| Your browser | About a minute |
Nameserver delegation at the registry (.com and similar) |
Often 24 to 48 hours, and you cannot change it |
| “Does not exist” answers (negative caching) | Controlled by the zone’s SOA timer, often 1 hour |
That fourth line explains why changing nameservers can take up to two days, while changing an A record with a low TTL takes minutes. And the fifth explains a classic trap: if you visit a new name before creating its record, the “does not exist” answer gets cached, and the name keeps failing for a while even after you add it.
6. Choose your migration path
| Path | What you change | Speed | Risk | Choose it when |
|---|---|---|---|---|
| A. Keep DNS, change the records | Only the A / AAAA records (and www) | Minutes to hours (your TTL) | Low | You are happy with where your DNS is managed. Recommended in most cases. |
| B. Move DNS with the hosting | Nameservers at the registrar | Up to 48 hours | Medium: you must rebuild every record | The old DNS host will be cancelled together with the old web host |
| C. Move DNS to a neutral DNS provider | Nameservers once, then records forever | Up to 48 hours once | Medium once, then low | You change hosts often and want DNS independent of any web host |
Whichever you pick, do not cancel the old hosting on the day of the move. Keep it running for at least a week.
7. Path A: keep your DNS and just switch the records
Step 1: Take a full inventory of the current records
Open your DNS panel and copy every record into a text file: A, AAAA, CNAME, MX, TXT, SRV, CAA, and also the subdomains (mail, webmail, blog, shop…). Then double-check from the outside, because panels can hide things:
dig +short example.com A
dig +short example.com AAAA
dig +short www.example.com
dig +short example.com MX
dig +short example.com TXT
dig +short _dmarc.example.com TXT
dig +short selector1._domainkey.example.com TXT # use your own DKIM selector
If you are unsure how to read the output, the guide on DNS troubleshooting with dig and nslookup explains every line.
Step 2: Lower the TTL, then wait
In your DNS panel set the TTL of the A, AAAA and www records to 300 seconds (5 minutes). Then wait at least as long as the previous TTL (if it was 14400, wait four hours; if it was 86400, wait a full day). Only after that wait does the whole world hold the short TTL.
Step 3: Build and test the site on the new host, before touching DNS
Copy the files and the database to the new server and make it work. You can test it under the real domain name without changing DNS, by pretending the name points to the new server on your computer only.
Option 1: the hosts file. Add one line (use the new server’s IP):
# Linux / macOS: /etc/hosts
# Windows: C:\Windows\System32\drivers\etc\hosts (edit as Administrator)
203.0.113.50 example.com www.example.com
Option 2: no file edit, one command:
curl -I --resolve example.com:443:203.0.113.50 https://example.com/
Remove the hosts line afterwards, or you will keep seeing the new server and forget you are not testing the real thing.
Step 4: Prepare the certificate (HTTPS)
Browsers will complain if the new server has no valid certificate for your domain at the moment of the switch. Free certificates from Let’s Encrypt normally prove ownership by visiting your domain, which still points to the old server. You have three clean options:
- Use the DNS challenge (a temporary TXT record), which works before the switch.
- Copy the existing certificate and key to the new server for the transition.
- Switch DNS first and request the certificate immediately after, accepting a few minutes of warnings. Not recommended for shops or logins.
Our guide to free HTTPS with Let’s Encrypt and Certbot shows the commands.
Step 5: Freeze the data, then switch
For a static site this step is trivial. For anything with a database (WordPress, a shop, a forum) data keeps changing on the old server while you migrate, and visitors who still hit the old server after the switch would write into the old database. So just before the switch:
- Put the old site in maintenance or read-only mode (disable comments, orders and logins).
- Take a final database export and import it into the new server.
- Check the new site once more with the hosts-file trick.
Then, in the DNS panel, change the A record of the bare domain and of www to the new IP. Delete the old AAAA record unless the new host gives you an IPv6 address. A stale AAAA record is the most common reason “it works for me but not for some visitors”: IPv6 users keep being sent to the old server.
Step 6: Watch and verify
Ask several public resolvers, not just your own computer:
dig +short example.com @8.8.8.8
dig +short example.com @1.1.1.1
dig +short example.com @9.9.9.9
Within minutes (with a 300-second TTL) they should all show the new IP. Also watch the access logs of both servers: traffic gradually drains from the old one to the new one. When the old server’s log goes quiet, the move is effectively complete.
Step 7: Clean up
- Raise the TTL back to a sensible value (3600 to 86400) so resolvers cache again.
- Keep the old hosting alive for at least one to two weeks, as a safety net and for any email still arriving there.
- Take a final backup of the old account before you cancel it.
8. Path B and C: changing the nameservers
Choose this when the old DNS host is going away with the old hosting, or when you want to move DNS to a dedicated provider. It is the same idea, with one big difference: while you change nameservers, the whole zone moves, so every record must exist at the new place first.
Step 1: Recreate the entire zone at the new DNS host, before changing anything
Add the domain at the new DNS provider. Many providers can import a zone file or scan the existing records, but never trust the import blindly. Compare against your inventory from Path A, step 1, record by record. Do not forget:
- every
MXrecord and its priority, - every
TXT: SPF, DKIM keys, DMARC, site verification codes, - subdomains (
mail,webmail,autodiscover,ftp…), CAAandSRVrecords.
Then test the new zone directly, before the world is told to use it, by asking the new nameserver itself:
dig @ns1.newprovider.com example.com A +short
dig @ns1.newprovider.com example.com MX +short
dig @ns1.newprovider.com example.com TXT +short
Compare each answer with the same query against the old nameserver. They must be identical, except for records you intentionally change (the web server IP).
Step 2: Check DNSSEC before anything else
DNSSEC adds cryptographic signatures to DNS answers. If your domain uses it, a DS record is stored at the registrar and ties the domain to the old provider’s signing keys. If you switch to nameservers that do not have those keys, validating resolvers will treat your domain as forged and refuse to resolve it: a total outage for a large part of the internet.
Check whether it is enabled:
dig +short DS example.com
If this prints a value, then before you change nameservers: remove the DS record at the registrar, wait for its TTL to expire (commonly up to 24 hours), switch nameservers, and only afterwards enable DNSSEC at the new provider and publish the new DS record. If it prints nothing, DNSSEC is off and you can skip this.
Step 3: Change the nameservers at the registrar
Log in to the registrar (where you renew the domain), find “Nameservers” or “DNS settings”, choose custom nameservers and enter the ones given by the new provider (usually two to four). Save. This does not move the domain registration and does not delete anything at the old provider.
Step 4: Keep both zones alive and identical for 48 hours
For up to two days, different resolvers will still ask the old nameservers (their cached delegation has not expired yet). During that window both the old and the new zone must answer correctly and identically. Do not delete the old zone, and make any record edit in both places until the transition is over. Tip: do the web server IP change in a separate step later (Path A) so that you never change two things at once.
Step 5: Verify the delegation
dig +short NS example.com @8.8.8.8
dig +short NS example.com @1.1.1.1
dig +trace example.com
The first two should list the new nameservers once caches expire. +trace bypasses caches and walks from the root down, showing exactly what the registry currently says. Once you only see the new nameservers everywhere, and about two days have passed, you can retire the old zone.
9. Email: the part people forget
Your website and your email use different records, and they can live on different providers. This is the most important safety fact in this guide:
- Moving only the website (Path A): do not touch
MXor the mail-relatedTXTrecords. Email keeps working exactly as before. - Moving nameservers (Path B/C): the MX and TXT records must be copied perfectly, otherwise mail to your domain bounces or vanishes the minute the new zone becomes active.
- Moving the mailboxes too: do it as a separate project, after the website move. Lower the MX TTL first, create the new mailboxes, copy existing mail with an IMAP migration tool, then change MX. During the overlap, some messages will arrive at the old server, so keep it running and check it for a few days.
When mail is involved, also review these three records, as providers often change them:
| Record | Check |
|---|---|
SPF (a TXT starting with v=spf1) |
Only one SPF record per domain, and it must list the new provider’s sending servers. Remove the old provider when they no longer send for you. |
DKIM (TXT at selector._domainkey) |
The new provider gives you a new key to publish. Keep the old one until old mail is no longer in flight. |
DMARC (TXT at _dmarc) |
Keep it as it is; it applies regardless of provider. Read the reports after the move. |
10. Troubleshooting: “it did not work”
| Symptom | Likely cause | What to do |
|---|---|---|
| You edited a record and nothing changed | The domain uses other nameservers than the panel you edited | Run dig +short NS example.com and edit the zone at that provider |
| Works on your phone, not on your PC (or the reverse) | Different resolvers hold different cached answers | Wait for the TTL. Flush your local cache (below) |
| Some visitors reach the old site for days | Stale AAAA record, or the old TTL was long | Delete or update the AAAA record. Next time lower the TTL a day earlier |
| Browser shows a certificate warning after the switch | New server has no certificate for the domain | Install it (see the HTTPS guide). Check that the www name is included |
DNS_PROBE_FINISHED_NXDOMAIN |
The name does not exist in the zone that is live, or negative caching | Check the record exists on the authoritative server, then wait for the SOA timer |
| Whole domain unreachable for some users after changing nameservers | DNSSEC DS record left at the registrar | Remove the DS record at the registrar immediately |
| Email stopped after moving DNS | MX or TXT records not copied | Compare the new zone with your inventory and restore the missing records |
| Bare domain fails, www works | No A record on the bare domain (a CNAME is not allowed there) | Add an A record or use your provider’s ALIAS feature |
Flush your own computer’s cache while testing:
# Windows
ipconfig /flushdns
# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
# Linux with systemd-resolved
sudo resolvectl flush-caches
Remember that flushing your computer does not flush your ISP’s resolver. To see the real current state, query authoritative servers directly (dig @ns1.provider.com ...) and public resolvers (dig @8.8.8.8 ...).
11. The safe-migration checklist
A few days before
- Export or copy every DNS record. Check with
digfrom outside. - Check DNSSEC (
dig +short DS example.com). - Lower the TTL of the records you will change to 300 seconds. Wait at least the previous TTL.
- Build the new site and test it with the hosts file or
curl --resolve. - Prepare the certificate on the new server.
Switch day
- Freeze content on the old site and do the final data sync.
- Change A (and delete or update AAAA). Change nameservers only if you chose Path B or C, as a separate step.
- Verify with several public resolvers and watch both servers’ logs.
- Test the site, forms, logins, payments and email sending and receiving.
The following days
- Keep the old host and the old zone alive for one to two weeks.
- Raise the TTL back to 3600 or higher.
- Take a final backup of the old account, then cancel it.
12. Quick answers
How long does a DNS change take? For a record: up to the old TTL (minutes if you prepared, up to a day if you did not). For nameservers: plan for up to 48 hours.
Will my site go down? Not if both servers serve the site correctly during the overlap. During the transition some visitors reach the old server and some the new one, and both must work.
Do I need to transfer my domain to the new hosting company? No. A domain transfer is a separate paid operation at the registrar. You never need it just to host the site elsewhere.
Should I use my host’s nameservers or a separate DNS provider? Using your host’s nameservers is simplest. A separate DNS provider costs a little more effort once, and makes every later hosting change as simple as editing one IP address.
Which is safer, changing the A record or the nameservers? Changing the A record. It touches one thing, is fast, and is easy to undo by putting the old IP back. Change nameservers only when you really need to.
More tutorials like this
Why Is My Website Slow? Measure DNS, TLS and Server Time with curl
Use curl to split a web request into DNS, connection, TLS, server and download time, read the numbers correctly and fix the slow part.
How a Network Works: IP and MAC Addresses, Switches, Routers and the Path of a Packet
Learn how a network really works: IP and MAC addresses, how a switch and ARP deliver frames in the LAN, how the router and…
tcpdump Tutorial: Capture and Read Network Traffic on Linux
Capture and read network traffic with tcpdump: key options, filters, a real TCP handshake explained line by line, and pcap files for Wireshark.


