DEV Community

Joel Varty
Joel Varty

Posted on

DNS 101 For Web Developers

As web developers, DNS is one of the least understood aspects of the internet. It's also one of the most important, as it's the glue that links your domain name (yourwebsite.com) to your website that's hosted on a web server.

DNS stands for Domain Name Service

What we are talking about here is the ability for people who are browsing the internet at your web address to be directed the IP Address of the server that is hosting your website. It connects the Domain Name, to the IP Address. An IP Address is a series of 4 numbers between 0 and 255 that each web host should be able to give you.

There are a few different ways that we can achieve this.

The "A" Record

This is the most basic type of record. It says point this address (yoursite.com) to this IP Address (1.1.1.1).

For each top-level domain you should have 1 A Record. That should be used to connect your top-level website address to your web hosting IP Address.

yoursite.com 1.1.1.1

Resist the temptation to create A records for all your subdomains (www.yoursite.com, blog.yoursite.com, files.yoursite.com). That way lies madness! Why? If you ever move web hosts, you don't want to have to change all these A records!

We can use a different method for those.

The "CName" Record

A CName points one web address (www.yoursite.com) to another one (yoursite.com). The most common usage of this is to send traffic from your subdomains (eg: www.yoursite.com) to your top-level domain (yoursite.com).

www mysite.com.

Many tools use the @ symbol to represent your top-level domain.

www @

In other situations, you need to point a subdomain (eg: files.yoursite.com) to another address given to you be an address given to you by online service, such as Netlify, Cloudflare, or Azure CDN.

www xyz.netlify.com.

Notice that some DNS providers require you to add the dot (.) after the address you are pointing other, otherwise they will create a link between subdomains (www.yoursite.com -> xyz.netlify.com.yoursite.com) which is not what you want.

The "TXT" Record

Normally, a TXT record is used to verify that you own a domain. You will be asked to put a unique identifier your TXT record that is provided by the service.

Other DNS Record Types

There a many other DNS record types (MX, SPF, etc.) As a web developer you probably won't need to work with those very often. If you do, let me know in the comment.

Name Servers

DNS Records can be hosted separately from your actual DNS name. They are hosted by your Name Servers. There are usually 2, sometimes 3 of these to provide redundancy. When you setup using some hosting services, they will ask you to point to their name servers. That way they can help you with common settings for their service.

This can become confusing if you've setup all your DNS records in one spot, but have indicated on your actual DNS host to point to name servers - so be sure to document that somewhere.

Diagnostics

This is getting beyond the scope of this article, however there are a view tools you can use to check what the DNS settings are for a particular domain name.

Use ping to check A record (IP Address) or CName

ping www.yoursite.com
Enter fullscreen mode Exit fullscreen mode

Online tools such as dnschecker.org can also tell you where your DNS settings have been propagated to worldwide.


I hope you find this helpful!

Top comments (8)

Collapse
 
chrisrhymes profile image
C.S. Rhymes

Top tip, if you transfer your domain, remember to set your dns settings on your new provider... 🤦‍♂️(speaking from personal experience)

Also I found using dig www.yoursite.com a useful tool to see where domains redirect to.

Collapse
 
joelvarty profile image
Joel Varty

Nice tip!

Collapse
 
andreasjakof profile image
Andreas Jakof • Edited

Since IPv4 is considered "historic" for a while now, there is another record type, which is becoming more and more important:

AAAA Records are much like A Records, but instead of using IPv4-Addresses, they map the name to an IPv6 Address.

Collapse
 
andreasjakof profile image
Andreas Jakof

Just for some comparison of address space between IPv6 and IPv4

IPv4: 2^32  =                                       4,294,967,295 
IPv6: 2^128 = 340,282,366,920,938,463,463,374,607,431,768,211,456
Collapse
 
joelvarty profile image
Joel Varty

Agreed! This is going to be more and more important moving forward!

Collapse
 
pim profile image
Pim • Edited

Amazing article and such an important subject that is often looked past. Also important to do a DNS Leak test!

Collapse
 
ineedale profile image
Alex Leonhardt

Just the title reminded me of twitter.com/ryan_sb/status/7634543... :)

Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

This is great! Would love to see a follow up with the other record types.