DNS or Domain Name System is a protocol that translates domain names into IP addresses that computers can understand.
Without such a system, users will have trouble accessing their favorite websites. Imagine having to type in numbers like 188.8.131.52 every time you want to visit Twitter. Not only is it impractical, but it also does not show any information about the website you’re heading to.
If you run a website, chances are you’ve encountered DNS configuration on your hosting admin panel. This is where you create DNS records, the settings that point your domain name to the appropriate IP address.
In this article, I will talk more in-depth about how DNS works, different types of DNS records, and how to set them up.
How does DNS Work?
We’ve established the basic function of DNS, but how does it work, exactly?
To give you a more detailed picture of this system, here’s what happens when you visit a website:
- When you enter a domain name, your browser will search for the associated IP address in its local memory. If it couldn’t find any, it will send a query to the DNS server of your internet service provider (ISP).
- The DNS server will search its memory to find the right information. If it doesn’t have the requested information, the query will be continued to the next server until the correct data is obtained.
- After that, the DNS server that has the correct information will send the IP address down the line to the requesting DNS server until it reaches your computer.
- Your computer uses the IP address to exchange data with the host server, and display the website in your web browser.
DNS Tree Structure
As mentioned above, DNS queries can involve several servers in order to find the right IP address. This is related to the DNS tree structure, a hierarchy that helps in managing its distributed domain database.
Here are the elements of the DNS hierarchy:
- Root zone — the highest level in the hierarchy. When your browser sends a DNS query, it is received by root nameservers, which will lead you to the appropriate top-level domain nameservers.
- Top-Level Domains (TLD) — the extension of a domain name. A TLD nameserver contains information about all domain names that share a common extension. For instance, .com nameserver will have a list of all domain names that end with .com.
- Second-Level Domains — a domain that is below the TLD, located to the left of the domain extension. In wordpress.com, for instance, wordpress is the second-level domain.
- Subdomains — a domain that is part of the main domain name. Some examples are maps.google.com, developer.wordpress.com, and help.twitter.com.
After reaching the TLD nameserver, the query is forwarded to the authoritative nameservers. These are the ones that hold the actual DNS records and information about second-level domains and subdomains. More on this later.
How to Set Up Nameservers for a Website
Nameservers, sometimes spelled as name servers, are servers that store DNS records.
If you use Hostinger, for example, your domain would point to two authoritative nameservers: ns1.dns-parking.com or ns2.dns-parking.com. The nameservers will change depending on the web or DNS service you’re using.
To configure your nameservers in Hostinger, open your hPanel, and click Hosting -> DNS Zone Editor. Scroll down until you find NS (Nameserver), and edit the fields with the corresponding information.
DNS Record Configuration
A DNS record is a setting that allows you to map your domain to a web service, such as an email or web hosting. There are four common types of DNS records, and I’ll cover them in the following sections.
A Records point a domain name to an IP address, specifically the IPv4 addresses. If you are using an IPv6 address, use AAAA records instead.
Using the example above, the @ symbol points to your root domain. This shows that your domain points to 184.108.40.206.
You can set up your domain or subdomain to various IP addresses by clicking on Add New. All you have to do is fill the Host field with the @ symbol and enter the IP address in the Points to field. For the TTL, most providers usually use 14400.
Once you’re done, click on Create and you’re done.
CNAME is short for Canonical Name, and is a record that maps an alias domain to your main domain name. This record is mostly used to associate a www subdomain to the primary domain.
Using the example below, this means that www.example.com will point to example.com.
To create a new alias, click Add New and fill in the required fields. They are quite similar to A Records, but what you input is different. The Host field is where you input the alias, and you place the target domain name in the Points to field.
MX Records points your domain to a mail server. In Hostinger, domain names will use mx1.hostinger.com and mx2.hostinger.com.
You can also use this record if you want to use a mail service with a domain name you’ve purchased beforehand. To add, click on Add New and fill in the details.
There are two different fields for this record: Priority and Points to. For the Priority field, the lower the number, the higher the priority. You then fill in the address of the email server in the Points to field.
TXT Records contain text information for sources that are outside of your domain. It gives information to other services about your domain, such as what services it’s connected to and how it is set up.
An example of its usage is the Sender Policy Framework (SPF) record. This lets the Internet know what email servers you are using and helps reduce spam by matching the sending address to the domain’s SPF record. If it doesn’t match, the message can go to the spam folder.
Click on Add New to create a new TXT record. There are three fields you need to fill out: Host, TXT value, and TTL.
For the TXT Value, you will input the information you want to specify. If you want to input an SPF record to authorize Google mail servers, you will fill in “v=spf1 include:_spf.google.com ~all” as the value.
To recap, DNS stands for Domain Name System and associates your domain with an IP address. The DNS records are stored in nameservers, which you can configure through the admin panel of the web service provider you’re using.
There are four main DNS records to configure: A Records, CNAME Records, MX Records, TXT Records. Each of them associates your domain name with a specific action.
I hope this article has answered your questions about DNS. Should you have any questions, leave it in the comment section below.