Hosting

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 name being connected to a web hosting server through DNS

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 nameserversAdd an A record
What it meansThe hosting company now manages all DNS for the domainThe DNS stays where it is; you only point the address to the server's IP
Best forShared hosting with cPanel or hPanel, where the host sets everything upA VPS, Cloudflare, or when email must stay where it is
What you needTwo nameserver names, such as ns1.example-host.comThe server's IP address, such as 203.0.113.10
Watch outRecords you added at the old DNS (email, verification) are gone and must be added again at the hostYou 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.com and dns2.namecheaphosting.com.
  • Hostinger: ns1.dns-parking.com and ns2.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

  1. Sign in to GoDaddy and open My Products, then Domains, and click your domain.
  2. Open DNS, then the Nameservers tab, and click Change Nameservers.
  3. 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

  1. In your Namecheap account, open Domain List and click Manage next to the domain.
  2. 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.
  3. 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>
PartWhat it does
The two preg_replace linesAccept 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_CNAMEThe IP of the domain and of www, and where www points
The ip checkCompares 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

ProblemCause and fix
Email stopped working after changing nameserversThe 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 showsThe 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 reachedNo A record, or the IP has a typo
The host's “default page” or a 404 appearsDNS 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 warningThe 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?

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:

Where to go next

Questions people ask

How do I connect my domain to my hosting?
Either change the domain's nameservers to the two your host gives you, so the host manages all DNS, or keep the DNS where it is and point an A record for @ to the hosting's IP, plus a CNAME for www. Then add the domain in your hosting account.
Should I change nameservers or add an A record?
Change nameservers for shared hosting where the host sets everything up. Use an A record for a VPS, for Cloudflare, or when your email and other records must stay where they are.
How long does it take to connect a domain to hosting?
An A record change usually works within minutes to an hour. A nameserver change takes a few hours for .com and .net domains and up to 24 to 48 hours everywhere.
How do I connect a GoDaddy domain to Hostinger?
Add the website with your domain in hPanel, then in GoDaddy open the domain's DNS, Nameservers, Change Nameservers, choose your own nameservers, and enter ns1.dns-parking.com and ns2.dns-parking.com.
What are Namecheap's nameservers for shared hosting?
dns1.namecheaphosting.com and dns2.namecheaphosting.com. If both the domain and the hosting are at Namecheap, choose Namecheap Web Hosting DNS in the domain's settings instead.
How do I connect my server to a domain?
Add an A record named @ with your server's public IP, and a CNAME named www pointing to your domain. Then set up the website on the server and issue an SSL certificate once the domain points to it.
How can I connect a domain to a website for free?
Static sites can use GitHub Pages or Cloudflare Pages with your own domain for free. PHP sites can use a free host such as InfinityFree, which accepts your domain through its nameservers. You still pay for the domain itself.
How do I host a website if I already have a domain?
Buy hosting (or use a free host to learn), connect the domain to it with nameservers or an A record, add the domain in the hosting account, then upload your website and turn on SSL.
Is domain flipping illegal?
No. Buying domains and selling them for profit is legal. Registering domains that copy a company's trademark to sell to them or mislead people (cybersquatting) is not, and can be taken away through a dispute process.
Why does my domain still show the old website?
The DNS change has not reached your network yet, or your computer remembers the old answer. Flush your DNS cache, check with nslookup against 8.8.8.8, and wait for the change to spread.

Written by Habib Baloch

I build Android apps, websites and Ubuntu servers, and write down exactly how I did it.

Ask me about this guide →