DNS for Beginners or How Do I Connect a Domain to My Website?

Building websites is fun and easy but unfortunately the http://localhost: domain and IP addresses aren’t accessible to the public. So now that the site’s done, you bought a domain, and picked out a web host you need to hook up it all up for the public to see. How does that all work!? Don’t worry, it’s easy. I’ll explain how DNS works and, more importantly, how it’s used to hook domain names up to web hosts so the whole world (except China and North Korea) can see the beautiful sites you’re building.

What is DNS?

The domain name system (DNS) is sort of like the street address system but for the internet. Let’s dive into how it works and what roles your domain name and web host play in this system. After reading this article you’ll go from thinking of DNS as a confusing tangle of interconnected “stuff” to a well organized system of pipes.

Domains and DNS

When you buy a domain name from a company like GoDaddy (don’t use them, I only mention them because they’re well known- use Namecheap or Google Domains instead) the company will automatically assign “nameservers” to your domain.


A nameserver is a special server that holds the addresses that belong to a domain. They basically hold the IP address of your server and match it with your domain name. They also hold other information like your personal info (you’re required to give a valid name, address, etc. when you register a domain).

Your nameservers will likely be set by default to your registrar’s settings and when you go to your newly bought domain you’ll see some sort of coming soon page or an ad for your registrar.

Hosting and servers

When you buy a domain you need a server to host your website on. With shared hosting all of that stuff is usually set up for your when you register a domain through your host. But if you’re reading my articles you’re either a beginner or intermediate developer trying to understand the full stack so we’re going to assume your registrar and host are two separate entities.

I choose either Linode or DigitalOcean for my hosting needs. When I do that I transfer my nameservers to my hosting provider because hosting is critical and I want to control my DNS settings and my server settings in the same place.

To change your nameservers you’ll need to log into your registrar and navigate to the DNS settings and change your domains nameservers to the ones provided by your hosting. There are usually between 2 and 5. Why so many? Just as a backup. Once you do change your nameserver settings you can go back to your web host and change all of your domain info at your web host. Just be careful – it takes up to 72 hours for DNS changes to take effect (most of the time 24 hours is the most you’ll wait).

Host settings

Now that your domain’s DNS settings can be controlled at the host level you can now set up what are called your A, CNAME, and MX records.

An A record makes sure that your domain resolves to the correct server via IP address.

A CNAME is like a shortcut record. It points one domain or a sub domain (like whatever.mydomain.com) to a different domain whose A records will fully resolve it.

MX records are for email. If you use Gmail as your email host, or any other email provider, they’ll give you a set of MX records you need to add to your DNS records.

So how does it all work?

You buy a domain. You change your domain’s nameservers to the ones provided by your host. You set up your A records and other important records that resolve an IP address to a server.

The last step is to set up your server to handle web requests. Working with your own web server like a VPS can be tough for a beginner which is why many newbies resort to shared hosting where everything is already set up for you. But if you’re going to grow as a developer it’s important to understand how to set up a server and part of that is understanding the basics of how the DNS system works.

In the end, DNS is matching a name with an IP address. Your nameservers point to your host records and those records do the final work of resolving a human readable address into an IP address so your request to view your friend’s Facebook profile can be successfully routed and connected.

Server administration, Web development

« Breaking the rules of the MEAN Stack Staying current as a developer »