How to Connect a Domain to Hosting (GoDaddy, Namecheap, Hostinger and Your Own Server)
Point your domain to your hosting with nameservers or an A record: step by step for GoDaddy, Namecheap, Hostinger, Cloudflare, a VPS and free hosts, how long it takes, how to check it, and the mistake that silently breaks your email.
A domain and a hosting account are two separate things, often bought from two different companies. Connecting them means telling the internet: “when someone types yourdomain.com, send them to this server”. That is done in the domain's DNS settings, and there are only two ways to do it.
This guide shows both ways, step by step for GoDaddy, Namecheap, Hostinger, Cloudflare, your own VPS and free hosting, then how to check it worked and the one mistake that silently breaks email.
Nameservers or an A record: which one?
| Change the nameservers | Add an A record | |
|---|---|---|
| What it means | The hosting company now manages all DNS for the domain | The DNS stays where it is; you only point the address to the server's IP |
| Best for | Shared hosting with cPanel or hPanel, where the host sets everything up | A VPS, Cloudflare, or when email must stay where it is |
| What you need | Two nameserver names, such as ns1.example-host.com | The server's IP address, such as 203.0.113.10 |
| Watch out | Records you added at the old DNS (email, verification) are gone and must be added again at the host | You add every record yourself |
Step 1: Find your hosting's nameservers or IP
- cPanel hosting: the welcome email lists the nameservers. The IP is on the right side of cPanel's home page as Shared IP Address.
- Namecheap shared hosting:
dns1.namecheaphosting.comanddns2.namecheaphosting.com. - Hostinger:
ns1.dns-parking.comandns2.dns-parking.com. hPanel also shows them when you add a domain. - A VPS: the server's public IP, shown in the provider's panel.
- Free hosting: InfinityFree and similar hosts show their nameservers in the client area.
Always copy them from your own account: hosts sometimes give different values per server.
How to connect a domain to hosting at GoDaddy
- Sign in to GoDaddy and open My Products, then Domains, and click your domain.
- Open DNS, then the Nameservers tab, and click Change Nameservers.
- Choose I'll use my own nameservers, enter the two from your host, and save.
To use an A record instead, stay on the DNS Records tab and edit the A record named @ to your hosting's IP.
GoDaddy domain to Hostinger hosting
In hPanel, add the website with your existing domain. Then at GoDaddy, set the nameservers to ns1.dns-parking.com and ns2.dns-parking.com as above. hPanel shows the domain as connected once the change has spread.
GoDaddy domain to Namecheap hosting
At GoDaddy, set the nameservers to dns1.namecheaphosting.com and dns2.namecheaphosting.com. In your Namecheap cPanel, add the domain (as the main domain, or under Domains as an extra one) so the hosting knows to answer for it.
How to connect a domain to hosting at Namecheap
- In your Namecheap account, open Domain List and click Manage next to the domain.
- Under Nameservers, choose Custom DNS and enter your host's two nameservers. If the hosting is also at Namecheap, choose Namecheap Web Hosting DNS instead.
- Click the green check mark to save.
For an A record, choose Namecheap BasicDNS, open Advanced DNS, and add the records shown in the next section.
How to connect your own server (VPS) to a domain
Keep the DNS at your registrar or at Cloudflare and add two records. @ means the domain itself:
Type Name Value What it does
A @ 203.0.113.10 yourdomain.com goes to your server
CNAME www yourdomain.com www.yourdomain.com goes to the same place
On Cloudflare, add the same records under DNS. The orange cloud (Proxied) hides your server's IP and adds Cloudflare's cache; set SSL/TLS to Full (strict) once your server has its own certificate. Use the grey cloud (DNS only) for things that are not websites, such as a VPN or a mail server.
How to connect a domain to a website for free
Static sites (HTML, CSS and JavaScript) can live on free hosts that accept your own domain:
- GitHub Pages: add your domain in the repository's Settings, Pages, then add these records and tick Enforce HTTPS:
Type Name Value
A @ 185.199.108.153
A @ 185.199.109.153
A @ 185.199.110.153
A @ 185.199.111.153
CNAME www yourusername.github.io
- Cloudflare Pages: open the project, Custom domains, and add your domain; if the domain is already on Cloudflare, the records are added for you.
- PHP sites: free hosts such as InfinityFree accept your own domain through their nameservers. See how to host a PHP website for free.
Step 2: Tell the hosting about the domain
DNS sends visitors to the server, but the server must also know which site to show. On cPanel, a domain bought elsewhere is added under Domains (older versions call it Addon Domains); on hPanel, add it as a website; on a VPS, add it in your control panel or web server settings. After the domain points to the server, issue the free SSL certificate (cPanel: SSL/TLS Status, Run AutoSSL).
Check that it is working
From any computer's terminal:
# Windows, macOS or Linux: which nameservers does the domain use now?
nslookup -type=ns yourdomain.com
# Which IP does it point to? (asking Google's DNS, not your own computer's cache)
nslookup yourdomain.com 8.8.8.8
# Windows: forget old answers your own computer remembered
ipconfig /flushdns
Or upload this small page to any PHP hosting and open dns-check.php?domain=yourdomain.com&ip=203.0.113.10. It shows the nameservers and the addresses of the domain and its www, and whether they point to your server:
<?php
// dns-check.php: is my domain pointing to my hosting yet?
// Open dns-check.php?domain=yourdomain.com&ip=203.0.113.10 (the ip part is optional)
$domain = strtolower(trim($_GET['domain'] ?? ''));
$domain = preg_replace('#^https?://#', '', $domain);
$domain = preg_replace('#[/:].*$#', '', $domain);
$expect = trim($_GET['ip'] ?? '');
$valid = (bool)preg_match('/^(?=.{4,253}$)([a-z0-9-]+\.)+[a-z]{2,}$/', $domain);
function records($name, $type) {
$found = @dns_get_record($name, $type);
return is_array($found) ? $found : [];
}
$lines = [];
if ($valid) {
$ns = array_column(records($domain, DNS_NS), 'target');
$lines[] = ['Nameservers', $ns ? implode(', ', $ns) : 'none found: the domain may not be registered or set up yet'];
foreach ([$domain, 'www.' . $domain] as $host) {
$a = array_column(records($host, DNS_A), 'ip');
$cname = array_column(records($host, DNS_CNAME), 'target');
$text = $a ? implode(', ', $a) : 'no A record';
if ($cname) { $text .= ' (CNAME to ' . implode(', ', $cname) . ')'; }
if ($expect !== '' && $a) {
$text .= in_array($expect, $a, true) ? ' ✔ points to your server' : ' ✘ not your server yet';
}
$lines[] = ["Address of $host", $text];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>DNS check</title>
<style>body{font-family:system-ui,sans-serif;max-width:720px;margin:30px auto;padding:0 16px}input,button{padding:9px;font:inherit}td{padding:8px 12px;border-bottom:1px solid #ddd;vertical-align:top}</style>
</head>
<body>
<h1>DNS check</h1>
<form>
<input name="domain" placeholder="yourdomain.com" value="<?= htmlspecialchars($domain) ?>" required>
<input name="ip" placeholder="server IP (optional)" value="<?= htmlspecialchars($expect) ?>">
<button>Check</button>
</form>
<?php if ($domain !== '' && !$valid): ?>
<p>That does not look like a domain name.</p>
<?php elseif ($lines): ?>
<table>
<?php foreach ($lines as [$name, $value]): ?>
<tr><td><?= htmlspecialchars($name) ?></td><td><?= htmlspecialchars($value) ?></td></tr>
<?php endforeach; ?>
</table>
<p>This shows what this server's DNS sees right now. Other networks may still see the old values for a few hours.</p>
<?php endif; ?>
</body>
</html>
| Part | What it does |
|---|---|
The two preg_replace lines | Accept https://yourdomain.com/page as well and keep only the domain |
dns_get_record(..., DNS_NS) | The nameservers: proof of which company manages the DNS now |
DNS_A and DNS_CNAME | The IP of the domain and of www, and where www points |
The ip check | Compares the answer with your server's IP and says yes or not yet |
How long does it take?
An A record change usually works within minutes to an hour, depending on the old record's TTL. A nameserver change typically takes a few hours for .com and .net, and up to 24 to 48 hours everywhere. During that time some visitors see the old site and some the new one; that is normal.
Common problems
| Problem | Cause and fix |
|---|---|
| Email stopped working after changing nameservers | The MX records stayed at the old DNS. Add your email provider's MX, SPF and DKIM records at the new DNS. |
| The old website still shows | The change has not reached your network yet, or your computer remembers the old answer. Run ipconfig /flushdns and check with nslookup yourdomain.com 8.8.8.8. |
| This site can't be reached | No A record, or the IP has a typo |
| The host's “default page” or a 404 appears | DNS works, but the domain was not added in the hosting (Step 2) |
yourdomain.com works, www does not (or the other way round) | One of the two records is missing |
| A privacy or certificate warning | The SSL certificate is issued only after the domain points to the server. Run AutoSSL again an hour later. |
I have a domain: how do I host the website?
- A normal website or PHP script: cheap shared hosting with cPanel. Compare plans with our cheap hosting guide, then follow how to upload a website to cPanel.
- For free, to learn: free PHP hosting or GitHub Pages for HTML.
- Apps that need a server: a VPS (shared vs VPS vs dedicated).
Many domains and many sites
Once you run several sites, a few habits save trouble: keep all DNS at one place (Cloudflare's free plan is popular for that), turn on the registrar lock and auto-renew so nobody can move or lose a domain, use two-factor login at the registrar, and keep a list of every record your email and services need, so a nameserver change never breaks them.
Something to put on your domain
All our PHP scripts install on a domain or subdomain in minutes, with a web installer and free SSL from your hosting:
- HTML5 game portal script: your own free-games website, with games, thumbnails and categories managed from the admin panel
- PHP blog script with admin panel
- Digital products shop
- Online web tools website