How to connect a domain to a server: DNS records, www and a provider move without downtime
You set A and AAAA on the apex and a CNAME on www, pick one version of the address with a 301 redirect, check the answers of several resolvers and move DNS to another provider so that neither the site nor the email disappears. We ran the commands against real domains and two local DNS servers.
A domain works when the registry points to its name servers, the NS records, and those answer with records that lead to the web and mail servers. After this guide the apex and www open the same site, one version redirects to the other, and changing DNS providers causes no downtime.
DNS propagation is really caching. A resolver keeps an answer for the time in the record's TTL and only then asks again, so a move starts with lowering the TTL, not with changing the address.
Level
beginner
Code
Bash
Steps
9 steps
DNSRecordsA and AAAA on the apex, a CNAME on www.
nginxOne version of the addressA 301 from www to the apex, path included.
TTLPreparationA 300-second TTL before any change.
ResultA move without downtimeThe new zone checked before you change NS.
What you need
Access to the registrar and the DNS provider
The registrar changes the domain's NS servers and the DNS provider keeps its records. They are often the same company, but they do not have to be: github.com, for example, has its zone with two providers at once.
The server's IPv4 address, and IPv6 if it has one
The AAAA record tells IPv6 users where to connect, so the IPv6 address must really serve the site. The examples use 192.0.2.10 and 2001:db8::10 from ranges reserved for documentation.
A terminal with dig and curl
On Ubuntu and Debian dig comes in the bind9-dnsutils package. We ran dig 9.18.39 and curl 8.5.0.
A certificate covering both names
A redirect from https://www works only when the certificate covers www. Without it the browser shows a connection error before it ever gets the 301.
The records that connect a domain to a server
Record
What it does
Example
A
the server's IPv4 address
example.com. 3600 IN A 192.0.2.10
AAAA
the server's IPv6 address
example.com. 3600 IN AAAA 2001:db8::10
CNAME
an alias for another name, never on the apex
www.example.com. 3600 IN CNAME example.com.
NS
the zone's name servers, changed at the registrar
example.com. NS ns1.example.com.
MX
the mail server, which stays as it is when the site moves
example.com. 3600 IN MX 10 mail.example.com.
Step by step
Each step with commands to copy. The list on the left shows where you are.
01
Check who serves the domain's DNS
dig NS shows the name servers, which is where you change the records. dig +noall +answer prints just the answers, with the TTL in the second column. www.github.com is a CNAME to github.com, and cloudflare.com has two AAAA records, so two IPv6 addresses.
Before you change anything, write the current records down: A, AAAA, CNAME, MX and every TXT. During a move you compare the new zone against this list.
www.github.com. 429 IN CNAME github.com.github.com. 32 IN A 140.82.121.4
Command
dig +noall +answer cloudflare.com AAAA
Output
cloudflare.com. 178 IN AAAA 2606:4700::6810:85e5cloudflare.com. 178 IN AAAA 2606:4700::6810:84e5
02
Set A and AAAA on the apex and a CNAME on www
The apex gets A and AAAA records with the server's addresses. www gets a CNAME to the apex, so when the server changes you fix the address in one place only. A resolver asking for www gets both records straight away: the alias and the address.
We published the records below on a local DNS server and queried it with dig, hence @127.0.0.1 -p 15353 in the commands. On your side you ask your provider's name server, such as @ns1.example.net, or leave out @ to ask the default resolver.
example.com.zone
; site: IPv4 address, IPv6 address and www as an alias of the apexexample.com. 3600 IN A 192.0.2.10example.com. 3600 IN AAAA 2001:db8::10www.example.com. 3600 IN CNAME example.com.
dig, a local test zone
Command
dig @127.0.0.1 -p 15353 +noall +answer example.com A
dig @127.0.0.1 -p 15353 +noall +answer www.example.com A
Output
www.example.com. 3600 IN CNAME example.com.example.com. 3600 IN A 192.0.2.10
03
Do not put a CNAME on the apex
RFC 1034 and 2181 say that a name with a CNAME record cannot have any other records. The apex always has SOA and NS, and usually MX and TXT too, so a CNAME does not belong there.
A DNS server will not always stop you. CoreDNS published a CNAME on example.net for us without complaint, and then answered the MX and TXT questions with the CNAME as well. A resolver then looks for the mail server and the SPF record in someone else's domain, shop.example.org.
If the host gives you only a name and no IP address, use your DNS provider's feature that turns a CNAME into an address. Cloudflare calls it CNAME flattening: the server finds the target's IP address itself and returns it instead of the CNAME record.
dig, a local zone with the mistake
Command
dig @127.0.0.1 -p 15353 +noall +answer example.net A
Pick one version of the address and redirect the other
Both versions are fine: github.com redirects www to the bare domain and cloudflare.com does the opposite, as the output shows. What matters is that the site has one address and the other version sends visitors there with a 301 that keeps the path and parameters. In nginx $request_uri does that.
The configuration below catches three cases: http on the apex, http on www and https on www. Each ends in a single redirect to https://example.com, with no chain of several 301s. We tested it in nginx 1.31.6 in Docker, and curl with --connect-to and --resolve sent the requests to that container instead of a real server.
The domain's name server, here ns1.hosti24.pl for vulcode.com, always gives the full TTL from the record: 3600 seconds. A public resolver gives what is left in its cache. 1.1.1.1 had held the answer for a while and was keeping it for another 1051 seconds. 8.8.8.8 and 9.9.9.9 showed the full 3600, so they had just fetched the record.
That is all propagation is: after a record changes, every resolver shows the new value at the latest once the TTL it remembered runs out. Asking the name server directly tells you what is in the zone. Asking resolvers tells you what users see.
dig, vulcode.com
Command
dig +short NS vulcode.com
Output
ns2.hosti24.pl.ns1.hosti24.pl.
Command
dig @ns1.hosti24.pl +noall +answer vulcode.com A
Output
vulcode.com. 3600 IN A 89.144.32.174
Command
dig @1.1.1.1 +noall +answer vulcode.com A
Output
vulcode.com. 1051 IN A 89.144.32.174
Command
dig @8.8.8.8 +noall +answer vulcode.com A
Output
vulcode.com. 3600 IN A 89.144.32.174
Command
dig @9.9.9.9 +noall +answer vulcode.com A
Output
vulcode.com. 3600 IN A 89.144.32.174
06
Lower the TTL before any address change
Change the TTL of the site's records to 300 seconds and leave the addresses alone for now. Wait as long as the old TTL, an hour here: by then no resolver holds a copy with TTL 3600. After the address changes everyone sees the new server within five minutes, and if something goes wrong, going back also takes five minutes.
Once the new server works, restore the longer TTL. A short TTL means more queries to the name servers but breaks nothing.
example.com.zone
; before the move: TTL 300 seconds, addresses unchangedexample.com. 300 IN A 192.0.2.10example.com. 300 IN AAAA 2001:db8::10www.example.com. 300 IN CNAME example.com.
dig, a local test zone
Command
dig @127.0.0.1 -p 15353 +noall +answer example.com A
Output
example.com. 300 IN A 192.0.2.10
Command
dig @127.0.0.1 -p 15353 +noall +answer www.example.com A
Output
www.example.com. 300 IN CNAME example.com.example.com. 300 IN A 192.0.2.10
07
Test the new server before you change DNS
curl --resolve connects to the IP address you give it but sends the real domain name, in TLS as well. That lets you check the certificate, the redirects and the site on the new server before you change a single record. In a browser an entry in /etc/hosts does the same.
Below, github.com answers 200 at its real address, while at an address from the documentation range curl ends with error 28, a connection timeout. That result on a new server means a firewall or a service that is not listening yet.
curl --resolve, github.com
Command
dig +short github.com A
Output
140.82.121.4
Command
curl -sI --resolve github.com:443:140.82.121.4 https://github.com/ | head -n 1
When you change DNS providers you copy the whole zone: the site's records, MX, every TXT with SPF, DKIM, DMARC and service verifications, and CAA and SRV if you have them. The new provider answers queries for your domain before you change NS, so you can ask its server directly.
The script below reads a list of names and types from a file, asks both servers and prints = for a matching answer or != with the difference. In our test the new zone was missing the DKIM key. After the NS change mail would still flow, but the DKIM signature would stop passing.
dns-compare.sh
#!/usr/bin/env bash# Compares the answers of the old and the new DNS provider before you change the NS servers at the registrar.# Usage: ./dns-compare.sh "@old-ns" "@new-ns" < records.txt (one name and type per line)old=($1)new=($2)while read -r name type; do [ -z "$name" ] && continue a=$(dig "${old[@]}" +short "$name" "$type" | sort) b=$(dig "${new[@]}" +short "$name" "$type" | sort) if [ "$a" = "$b" ]; then printf '= %-28s %s\n' "$name" "$type" else printf '!= %-28s %s\n' "$name" "$type" diff <(echo "$a") <(echo "$b") | grep '^[<>]' | cut -c1-90 fidone
You change the NS servers at the registrar, and the registry publishes them in the parent zone with its own TTL. For vulcode.com the .com server gives 172800 seconds, 48 hours, and the .pl server gives nask.pl 86400 seconds, 24 hours. That is how long resolvers may keep asking the old provider.
So the old zone stays untouched for at least that long, and any fix goes to both providers at once. You delete it only when dig NS shows the new provider from several resolvers.
nask.pl. 86400 IN NS ns.tpnet.pl.nask.pl. 86400 IN NS bilbo.nask.pl.nask.pl. 86400 IN NS eomer.nask.pl.nask.pl. 86400 IN NS kirdan.nask.pl.nask.pl. 86400 IN NS nms.cyf-kr.edu.pl.
How to check it works
We served the old and the new example.com zone on two CoreDNS 1.12.4 instances. dns-compare.sh found the DKIM key missing from the new zone, and once it was added every name on the list answered the same. We checked the redirects in nginx 1.31.6 in Docker, and the TTL and the delegation on real name servers.
We did not move a real domain between providers. The commands in steps 5 and 9 still show exactly the TTL values that decide how long a move takes.
Environment
CoreDNS 1.12.4 (old and new provider), nginx 1.31.6 in Docker, dig 9.18.39, curl 8.5.0
Result
Zones identical after adding the missing DKIM, a single 301 that keeps the path
What you should see
dig @new-name-server returns the same as the old one for every record on the list.
http://, http://www and https://www end in one 301 to the same address with the same path.
dig @1.1.1.1, @8.8.8.8 and @9.9.9.9 show the new address once the old TTL has passed.
Mail arrives, and MX and the mail TXT records are in the new zone.
HTTP/1.1 301 Moved PermanentlyLocation: https://example.com/pricing?plan=yearlyStrict-Transport-Security: max-age=31536000; includeSubDomains
1-8
Both zones answer the same
Every name in records.txt shows =, including s2026._domainkey, which was missing before.
9-12
https://www to the apex
One 301 with the full path and parameters, with the HSTS header already on the redirect.
The domain connected together with the hosting
How it looks in our project
Hand it over when the domain also carries email, when the move involves several providers at once, or when you cannot afford downtime in a store or on forms.
With VulCode web hosting we connect the domain and set up the www and non-www versions. With a website transfer we check the site on the new server under the real domain before DNS changes, and we move the email and DNS records together with the site.
DNSSEC: the DS record at the registrar matches the old provider's keys.
Switch DNSSEC off and wait out the DS TTL before changing NS.
Frequently asked questions
The questions that come up with this setup.
01
How long does DNS propagation take?
A change to an A record shows up at the latest once its TTL expires in the resolvers' caches. A change of NS servers depends on the delegation TTL: in .com the NS records have 172800 seconds, 48 hours, and in .pl 86400, 24 hours. How a .pl transfer and an NS change work is covered in our post on domain transfers and propagation time.
02
How do I point a domain registered at home.pl, OVH or nazwa.pl to an external server?
In the registrar's DNS panel, whether that is home.pl, OVH, nazwa.pl or another, you set A and AAAA records for the apex and a CNAME for www, pointing to the server's address. The change is visible at the latest once the TTL of the previous records runs out.
03
How do I check whether a DNS change is already visible?
Query the domain's name server and a few public resolvers with dig, for example 1.1.1.1, 8.8.8.8 and 9.9.9.9. The name server shows what is in the zone and the resolvers show what users see; once all of them return the new address, the change is visible.
04
Is it better with www or without?
Both are fine. github.com chose the address without www and cloudflare.com the one with it. What matters is that there is one and the other redirects to it with a 301 that keeps the whole path.
05
Can I put a CNAME on the apex?
Under RFC 1034 and 2181 no, because a name with a CNAME cannot have other records, and the apex has at least SOA and NS. Some providers, Cloudflare for example, offer CNAME flattening: the server turns the target into an IP address itself and returns that instead of the CNAME.
06
Does a DNS change affect email?
Yes, if MX or the mail TXT records are missing from the new zone. That is why you compare MX, SPF, DKIM and DMARC together with the site's records. The mail records are covered in the SPF, DKIM and DMARC guide.
07
How is a domain transfer different from a DNS change?
A transfer changes the registrar you pay for the domain. A DNS change changes the servers that answer with the records. You can do one without the other, and the records do not move by themselves in either case. A .pl transfer step by step is covered in our post on moving a company domain.
Sources
The documentation and specifications we compared the commands with.
Mailboxes on your company domain for PLN 79.99 a year: IMAP, SMTP, webmail, a spam filter, SPF, DKIM and DMARC, backups and moving your old email.
Other guides
SPF, DKIM and DMARC step by stepAn SPF record within the lookup limit, a DKIM key from openssl, DMARC with reports and the road to p=reject.
Security headers in nginxHSTS in stages, CSP with a nonce in Report-Only, nosniff, Referrer-Policy, Permissions-Policy and the add_header trap.
Tools
Website migration checklistA website migration checklist that protects rankings: the migration type, old URL inventory, 301 redirect map, testing, change of address and monitoring.
Website launch checklistGenerate a website launch checklist tailored to your site: staging, redirects, robots.txt, sitemap, canonical, hreflang, structured data and Search Console.