Skip to main content

Cloud and deployment · Intermediate · 20 min

Move your domain's DNS to Cloudflare without downtime

By Padding · Updated 18 Nov 2026
Cloudflare DNS (Free plan) · dig 9.20 on Ubuntu 26.04

You will move a live domain's DNS from its registrar to Cloudflare with every record copied and checked, mail still flowing, the web records proxied and DNSSEC signed by Cloudflare.

On this page

Moving DNS is mostly bookkeeping. The risky moment is the nameserver change at your registrar: from then on, some resolvers ask your old DNS host and some ask Cloudflare, and they keep doing that for a day or two. If both places give the same answers, nobody notices the move. If Cloudflare is missing one TXT record, your email may start landing in spam and you will not know why.

So the method here is to make Cloudflare an exact copy of your current zone before anything switches, prove it is a copy with dig, change the nameservers, and only then change anything else. Proxying through Cloudflare and DNSSEC come last, one at a time, so that if something breaks you know which change did it.

The examples use example.com, documentation IP addresses such as 203.0.113.10, and a working folder ~/dns-move-demo. Replace example.com with your own domain everywhere.

Step 1 · List every record you have now

Start with a full list of what your domain answers today. If your current DNS host offers a zone file export (often called "Export zone", "Download BIND file" or similar), download it and keep it. Cloudflare can import that file later, which saves typing.

An export is not always offered, and even when it is, you should check the live answers yourself. You cannot ask a DNS server for "everything" any more (most servers refuse ANY queries), so you ask for each name and type in turn. Make a folder and a list of the names you use:

Bash
mkdir -p ~/dns-move-demo && cd ~/dns-move-demo
cat > names.txt <<'EOF'
example.com
www.example.com
mail.example.com
_dmarc.example.com
google._domainkey.example.com
EOF

Add every subdomain you know of: api, shop, blog, autodiscover, the server you SSH into, verification records such as _github-pages-challenge-..., and so on. DKIM records live under <selector>._domainkey, and the selector is not discoverable through DNS. Find it in your email provider's admin console (Google Workspace uses google by default, Microsoft 365 uses selector1 and selector2) and add one line per selector.

Now write a small script that asks one nameserver for each name and record type, drops the TTL column so lists from two servers can be compared, and sorts the result. It also leaves out the NS records at the apex (the first name in names.txt), because those always name the DNS host you asked and so can never match between two hosts:

Bash
cat > dnsdump.sh <<'EOF'
#!/bin/sh
# Usage: sh dnsdump.sh <nameserver> <names-file>
server=$1
names=$2
while read -r name; do
  for type in A AAAA CNAME MX TXT CAA SRV NS; do
    dig +noall +answer @"$server" "$name" "$type"
  done
done < "$names" |
  awk -v apex="$(head -n 1 "$names")." '!($4 == "NS" && $1 == apex) { $2 = ""; print }' |
  sort -u
EOF

Find your current nameservers and dump the zone from the first one:

Bash
dig +short NS example.com
OLD_NS=$(dig +short NS example.com | head -n 1)
sh dnsdump.sh "$OLD_NS" names.txt | tee records-before.txt

Asking the authoritative server directly with @ means you see what it serves now, not something a resolver cached earlier.

Check it worked

Open records-before.txt. You should see one line per record, for example example.com. IN MX 10 mx1.mailhost.example. and a v=spf1 ... TXT line at the apex. Check it against what you know: every MX host, an SPF TXT record, a DMARC record at _dmarc, one DKIM record per selector, any CAA records, and an A or CNAME for every name that serves something. There is deliberately no NS line for example.com itself; NS lines for delegated subdomains do appear. If a name you listed has no line at all, it either does not exist or you mistyped it. Fix names.txt and run the dump again until the file matches the records shown in your current DNS host's dashboard.

Step 2 · Lower the TTLs a day ahead

TTL is how long resolvers may cache an answer. If your www record has a TTL of 86400 (one day) and you need to fix it straight after the move, some visitors keep the old answer for up to a day. Lowering TTLs ahead of time shortens that window.

At your current DNS host, change the TTL of each A, AAAA, CNAME and MX record to 300 seconds (five minutes), or the lowest value it allows. Then wait at least as long as the old TTL was, usually one day, before changing nameservers. Until the old value expires, resolvers may still hold copies cached under the long TTL.

This does not speed up the nameserver change itself. The NS records that point the world at your DNS host are published by the registry for your top-level domain (.com, .ng, .co.za), with their own TTL, often one to two days, which you cannot change. That is why both DNS hosts must give the same answers for a while after the switch.

Check it worked

Run dig +noall +answer @"$OLD_NS" www.example.com A again. The second column of the answer is the TTL the server now hands out, and it should read 300 (or your chosen value) instead of the old number. Write down the date and time you made the change. You may change nameservers once the old TTL has passed since then.

Step 3 · Add the domain to Cloudflare and copy the records

In the Cloudflare dashboard, go to the domains list and choose to onboard a domain. Enter the bare domain (example.com, not www.example.com) and pick the Free plan. Cloudflare offers to scan your existing records. A scan is a good start, but Cloudflare says itself that it does not always find everything, and it cannot guess subdomains you never told it about.

If you have a zone file from your old host, import it instead. On the zone's DNS Records page, open Import and Export and upload the file. Before you upload it, untick "Proxy imported DNS records". For the move, every record should be DNS-only (grey cloud), so Cloudflare hands out exactly the same IP addresses your old host does. You turn proxying on later, after the move.

Then go through the record list in the dashboard, one record at a time, beside records-before.txt:

  • Add anything missing. DKIM keys, verification TXT records and records on rarely used subdomains are the usual gaps.
  • Delete anything the scan invented that you do not use.
  • Set every A, AAAA and CNAME record to DNS only.
  • Leave out the old provider's NS records at the apex. Cloudflare manages those itself. Keep NS records for subdomains you have delegated elsewhere.
  • If your old host had an ALIAS or ANAME record at the apex, dig shows it as plain A records. In Cloudflare, add a CNAME at the apex pointing to the same target instead. Cloudflare flattens an apex CNAME into A records for you.

Long TXT values, such as a 2048-bit DKIM key, are where copying goes wrong. Paste the whole value in one piece, without the quote marks and spaces that some dashboards add between the 255-character chunks.

Check it worked

The Overview page shows the zone as pending and lists two assigned nameservers, something like ada.ns.cloudflare.com and bob.ns.cloudflare.com. Cloudflare's assigned nameservers already answer for a pending zone, so you can compare before switching anything. Use your own assigned name in place of ada:

Bash
cd ~/dns-move-demo
sh dnsdump.sh ada.ns.cloudflare.com names.txt > records-cloudflare.txt
diff records-before.txt records-cloudflare.txt && echo "Zones match"

You want Zones match and no other output. Each line marked < is a record only your old host serves, and each line marked > is a record only Cloudflare serves. Fix the record in the dashboard, run both commands again, and repeat until the diff is empty. The apex NS records are filtered out by the script, so they never show here. One expected difference: if you have CAA records, Cloudflare adds its own CAA entries for the certificate authorities it uses. Those > lines for CAA are fine, as long as your own CAA lines appear on both sides.

Step 4 · Decide which records will be proxied later

Proxied (orange cloud) means Cloudflare answers with its own IP addresses and passes HTTP and HTTPS traffic on to your server, adding caching and attack protection. Only A, AAAA and CNAME records can be proxied, and only web traffic works through the proxy. Make the decision now, on paper, so that the move itself changes nothing.

Write a short list in ~/dns-move-demo/proxy-plan.txt, one line per A, AAAA or CNAME record, marked proxy or dns-only:

  • Proxy: the apex and www if they serve a website, and web APIs on ports 80 or 443 that you want behind Cloudflare.
  • DNS only: mail and any host your MX records point to, IMAP, SMTP and webmail hosts that your email provider runs, the name you SSH into, database, VPN or game servers, anything on a non-web port, and CNAMEs that a third party asks you to leave alone (email provider and SaaS verification targets often say so).

MX, TXT, SRV and CAA records are never proxied, so they do not go on the list.

Proxying a record hides your server's real IP address from new visitors. If that address was already public in DNS for years, a DNS-only record on the same server (such as ssh.example.com) still gives it away. Point SSH at a different name or address if that matters to you.

Check it worked

proxy-plan.txt has a line for every A, AAAA and CNAME name in records-before.txt, and no host that receives email or SSH is marked proxy. If you are unsure about a record, mark it dns-only. You can switch it to proxied later in a single click, and switch it back the same way.

Step 5 · Turn off DNSSEC at the old host if it is on

DNSSEC lets resolvers check that answers really come from your DNS host. It works through a DS record held at the registry, which matches the old host's signing keys. Cloudflare's keys are different, so if the old DS record is still there when the nameservers change, validating resolvers (including 1.1.1.1 and 8.8.8.8) reject every answer with SERVFAIL and your domain disappears for their users.

Check whether a DS record exists:

Bash
dig +short DS example.com @1.1.1.1

If this prints nothing, DNSSEC is off and you can go to the next step. If it prints a line of numbers and a long hex string, log in to your registrar, find the DNSSEC section and remove the DS record. Then wait for that record's TTL to run out before you change nameservers. For most top-level domains this is between one and two days.

Check it worked

Run the same dig +short DS command again after the wait. It must print nothing. Do not continue until it does. If your registrar has no DNSSEC section but the command still shows a DS record, ask its support team to remove it.

Step 6 · Change the nameservers at your registrar

Before you do this, run the diff from the Cloudflare step once more. If anything changed at your old host since then, copy it to Cloudflare first.

Log in to your registrar, open the domain's nameserver settings, and choose custom nameservers. Remove every existing nameserver and enter only the two Cloudflare assigned to you, spelled exactly as shown on the Overview page. Leaving one old nameserver in the list is not a safe middle ground. Cloudflare will not activate the zone while other nameservers are listed.

Do not delete the zone at your old DNS host. Resolvers that cached the old NS records keep asking it for a day or two, and it must keep giving correct answers until they stop. Leave it in place for at least a week.

Registrars in Nigeria and other African ccTLDs. For a .ng domain the change goes through your accredited registrar's control panel, the same as any other domain. Some registrars handle .ng nameserver updates by hand, which can take a few business days. If yours does, raise the request early in the week and keep your old host's zone unchanged until the update has gone through. The same applies to other country domains whose registries are slower than .com.

Check it worked

Ask Cloudflare's public resolver which nameservers your domain now has:

Bash
dig NS example.com @1.1.1.1

Once the registry has the change, the answer section lists your two *.ns.cloudflare.com names and nothing else. To see where the delegation comes from rather than what a resolver remembers, follow it from the root servers down:

Bash
dig +trace example.com NS

The output walks from the root, to the servers for your top-level domain, to your domain. The block returned by the top-level domain's servers should list the Cloudflare names. If it still shows the old ones, the registry has not published the change yet. Wait and try again later. Within a few hours, often sooner, Cloudflare emails you and the domain's status turns Active in the dashboard.

Step 7 · Check the live answers and your email

With the nameservers changed, make one last full comparison against the server that is now in charge, your assigned Cloudflare nameserver (use your own name in place of ada):

Bash
cd ~/dns-move-demo
sh dnsdump.sh ada.ns.cloudflare.com names.txt > records-after.txt
diff records-before.txt records-after.txt && echo "Live answers match"

Run the full dump against an authoritative server, not a public resolver. When a name is a CNAME to a host outside your zone, such as www pointing at a hosting platform or autodiscover pointing at your email provider, an authoritative server answers an A query with the CNAME line only. A resolver such as 1.1.1.1 follows the chain and adds the target's A and AAAA records, so the diff would fill with > lines whose names are those targets, not your own names.

Then spot-check what the world sees through a public resolver rather than your own network's one, which may cache longer. Mobile data networks in particular sometimes hold answers past their TTL.

Bash
dig +short www.example.com @1.1.1.1
dig +short MX example.com @1.1.1.1
dig +short TXT example.com @1.1.1.1

Then test the services as well as the records:

  • Open the website on a phone using mobile data (not your Wi-Fi) and on your computer.
  • Send an email to your domain from an outside account, such as a personal mailbox, and reply to it.
  • Open the headers of the received reply (often "Show original") and check that SPF, DKIM and DMARC all show pass.

Check it worked

The diff prints Live answers match, apart from Cloudflare's extra CAA lines if you have CAA records (apex NS lines are filtered out, as before). The spot checks through 1.1.1.1 return the same addresses, MX hosts and SPF value as records-before.txt; for a www CNAME you see the CNAME target followed by its addresses, which is normal. The site loads on both networks, the test email arrives in the inbox (not spam) in both directions, and the headers show three pass results. If DKIM fails, the DKIM TXT value was probably cut short while being copied. Compare it character by character with the key in your email provider's console.

Step 8 · Turn on proxying, then DNSSEC

Wait until the domain has been Active for a day and the checks above stay clean. Then make the two remaining changes, one at a time.

Proxying. In the DNS Records page, switch each record marked proxy in proxy-plan.txt to Proxied. Before you do, open SSL/TLS in the dashboard and check the encryption mode. If your server already has a valid certificate (for example from Let's Encrypt), use Full (strict), which encrypts the link from Cloudflare to your server and checks its certificate. Flexible leaves that link unencrypted, and on a server that redirects HTTP to HTTPS it can send visitors round in a loop of redirects.

DNSSEC. In DNS Settings, choose Enable DNSSEC. Cloudflare shows the DS record values: key tag, algorithm (13), digest type (2) and digest. Copy them into the DNSSEC section at your registrar. If you use Cloudflare Registrar, it adds the record for you. If your registrar does not accept DS records yet, as with some .ng registrars during the 2026 rollout, leave DNSSEC off for now and try again later. An unsigned domain still works.

Check it worked

For proxying, run dig +short www.example.com A @1.1.1.1. Instead of your server's address you should see Cloudflare addresses, and the site should still load over https:// with a valid padlock. dig +short mail.example.com A @1.1.1.1 should still return your mail host's real address.

For DNSSEC, the Cloudflare dashboard shows DNSSEC as active once it sees the DS record, which can take a day or two. Then check from outside:

Bash
dig +short DS example.com @1.1.1.1
dig +dnssec example.com A @1.1.1.1

The first command prints a line starting with the key tag, then 13 2 and the digest that Cloudflare showed you. In the second, the flags: line of the header includes ad, which means the resolver checked the signatures and they validated. If you get SERVFAIL instead, the DS record at the registrar does not match: compare each field with Cloudflare's values, or remove the DS record while you sort it out.

After a week of clean checks you can delete the zone at your old DNS host and the ~/dns-move-demo folder.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.