You have a domain and a server, and now they need to find each other. Connecting them is done entirely in DNS, and there are two ways to do it: hand the whole domain over to your host's nameservers, or keep your DNS where it is and change only the records that matter.
This guide shows you how to choose between the two, how to find your server's IP addresses, how to make the change step by step, and how to verify it from the command line before your visitors notice anything. It finishes with HTTPS and the problems people run into most often. If DNS records are new to you, read What is DNS? first.
Two ways to connect a domain
| Change nameservers | Edit A and AAAA records | |
|---|---|---|
| What moves | The whole DNS zone: website, mail, every record | Only the names you edit |
| Where you work | At the registrar, then in the new host's DNS editor | In the DNS editor you already use |
| Best for | Web hosting where site, email and DNS live together | A VPS, or when email stays with another provider |
| Main risk | Forgetting to recreate mail and verification records | Leaving a stale AAAA record behind |
As a rule of thumb: if you are moving everything to a cPanel web hosting account, change the nameservers. If you are pointing a domain at a VPS or dedicated server and your email lives elsewhere, edit the records.
Find your server's IP addresses
You need the public IPv4 address, and the IPv6 address if the server has one.
- On a VPS or dedicated server, the addresses are in your order confirmation and the client area. You can also read them on the server itself:
ip -4 addr show scope global
ip -6 addr show scope global
Only use addresses marked scope global. Addresses starting with fe80:: are link-local and must never go into DNS, and private ranges such as 10.x, 172.16–31.x or 192.168.x aren't reachable from the internet.
- On cPanel web hosting, the shared IP address is shown in the General Information panel on the cPanel home page, and your host will tell you which nameservers to use.
Method 1: Change the nameservers
Changing nameservers moves authority for the entire zone. Do it carefully:
- Export or screenshot your current zone. Note every MX, TXT (SPF, DKIM, DMARC, verification codes), CNAME and SRV record. These are the ones that get forgotten.
- Prepare the zone at the new host. When you add the domain to a hosting account, the basic records are usually created for you. Add anything else from your list.
- Change the nameservers at your registrar. Replace all of the old nameservers with the new ones. Don't mix old and new: resolvers pick one at random, so visitors would get different answers.
- Wait and verify. Nameserver changes depend on the TLD's own TTL and can take several hours, occasionally up to a day or two.
Check which nameservers the world currently sees:
dig +short NS example.com
dig +trace example.com | tail -20
Warning: The most common outcome of a careless nameserver change is broken email. If the MX records don't exist in the new zone, incoming mail starts bouncing as soon as resolvers pick up the change.
Method 2: Edit the A and AAAA records
Here the zone stays where it is and you only update where the website points.
- Lower the TTL first. A day before the move, set the TTL on the records you will change to 300 seconds.
- Point the bare domain at the server. Edit the A record for
example.com(often shown as@) to your IPv4 address, and the AAAA record to your IPv6 address. - Deal with old AAAA records. If there is an existing AAAA record pointing to the old server, change or delete it. Otherwise IPv6 visitors keep landing on the old site.
- Point
wwwat the domain. Use a CNAME fromwwwtoexample.com. The bare domain itself can't be a CNAME, which is why it uses A/AAAA records. - Leave mail alone unless email is moving too. MX, SPF and DKIM records stay as they are.
The finished records look like this:
example.com. 300 IN A 203.0.113.10
example.com. 300 IN AAAA 2001:db8::10
www.example.com. 300 IN CNAME example.com.
Make the server answer for the domain
DNS only gets visitors to the right IP. The web server must also know the domain. On cPanel, add the domain as an addon or the primary domain; see How to add another domain to your hosting in cPanel. On a VPS running Nginx, include both names in the server block:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
}
The listen [::]:80 line matters if you published an AAAA record. Also make sure your firewall allows ports 80 and 443 over both IPv4 and IPv6. To get onto the server in the first place, see How to connect to a Linux VPS with SSH.
Verify the change
Ask the authoritative nameserver directly. It reflects your change immediately, regardless of caches:
dig +short NS example.com
dig @ns1.example.net +short example.com A
dig @ns1.example.net +short example.com AAAA
dig @ns1.example.net +short www.example.com
Then compare with a couple of public resolvers to see how far the change has spread:
dig @1.1.1.1 +short example.com A
dig @8.8.8.8 +short example.com A
Finally, test the web server for each name and protocol:
curl -4 -I http://example.com
curl -6 -I http://example.com
curl -I http://www.example.com
If the authoritative answer is correct but a resolver still returns the old IP, you are simply waiting for its cache to expire. Flushing your own cache helps for your computer, but not for everyone else.
Enable HTTPS once DNS is correct
Certificate authorities check that the domain points at the server requesting the certificate, so issue SSL only after DNS has switched. On cPanel, AutoSSL picks the domain up automatically once it resolves; see How to install an SSL certificate and enable HTTPS. On a VPS with Nginx, Certbot can issue a certificate for both names:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
If you have a CAA record, make sure it allows the certificate authority you are using.
Common problems and fixes
- Only
example.comor onlywwwworks. One of the names is missing either in DNS or in the web server configuration. Check both. - Some visitors see the old site. Look for a leftover AAAA record, or wait out the old TTL.
- Email stopped after changing nameservers. The MX and TXT records weren't recreated in the new zone. Add them back from your notes.
- Certificate errors after the move. The certificate was requested before DNS pointed to the new server, or it only covers one of the names. Reissue it.
- Nothing changes, whatever you edit. You are editing a zone that isn't authoritative. Compare
dig NS example.comwith the provider you are logged in to.
In short
Change the nameservers when you want your host to run all DNS for the domain, and edit A and AAAA records when only the website is moving. Lower the TTL in advance, never forget the mail records, verify against the authoritative nameserver, and request SSL once DNS is pointing to the right place.
Hosting your domain at Hostigan
Whether you point a domain to cPanel web hosting or to a KVM VPS with full root access and IPv4 and IPv6 addresses, the setup above applies. Compare our VPS plans, or register a new name on our domains page.
Frequently asked questions
No. Email is delivered according to the MX records, so you can move the website by editing A and AAAA records without touching mail, as long as the MX records don't point at the hostname you changed.