Domain Name System (DNS) - All You Need To Know to Configure It

DNS translates human-readable domain names into IP addresses. Learn how it works and how to configure your domain names in no time.

What is DNS

DNS stands for Domain Name System, which is a distributed system used to translate human-readable domain names (like www.example.com) into IP addresses (like 93.184.216.34) that computers can use to communicate with each other over the internet.

When a user types a domain name into their web browser or clicks on a link, their computer sends a DNS query to a DNS resolver (typically provided by their ISP or a third-party service like Google DNS). The resolver then sends a recursive query to the root name servers, which are operated by 12 different organizations around the world.

The root servers respond to the resolver with a referral to the appropriate top-level domain (TLD) server based on the domain name in the query (like .com, .org, .edu, etc.). The resolver then sends another recursive query to the TLD server, which responds with a referral to the authoritative DNS server for the specific domain in the query.

The authoritative DNS server, also known as a name server (NS), is responsible for storing the DNS records for the domain (like the A record that maps the domain to an IP address). The NS responds to the resolver with the requested DNS record, and the resolver caches the result and sends it back to the user's computer. The user's computer can then use the IP address to connect to the server hosting the website associated with the domain name.

DNS is a critical component of the internet infrastructure, and it enables users to access websites and other online services using human-readable domain names instead of having to remember numeric IP addresses.

Getting started with DNS configuration

Assuming you already have a domain name registered with a domain registrar, the first step is to create DNS records for the domain. You can do this through your domain registrar's control panel or through a separate DNS management service.

When you're using a domain registrar's web interface to configure DNS records, the interface will typically present a form or series of input fields where you can enter the various components of a DNS record. Here's how you can translate the DNS line "www.example.com. IN CNAME example.com" into the corresponding fields on a DNS web interface:

Record type

The first component of the DNS line, "IN", specifies the class of the record and is typically not needed when configuring DNS records through a web interface. Instead, you'll typically select the record type from a drop-down menu or list of options. In this case, you would select "CNAME" as the record type.

Name

The second component of the DNS line, "www.example.com.", specifies the domain name that you're configuring the record for. In the DNS web interface, this will typically be presented as a text input field labeled "Name" or "Hostname". Enter "www" or "www.example.com" (without the period at the end) in this field.

Value

The third component of the DNS line, "example.com", specifies the target domain or IP address for the record. In the DNS web interface, this will typically be presented as a text input field labeled "Value", "Target", or "Points to". Enter "example.com" (without the period at the end) in this field.

Once you've filled in these fields, you can typically set any additional options for the record, such as TTL or priority, and save the changes to update the DNS configuration.

It's important to note that the specific layout and terminology of DNS web interfaces can vary depending on the DNS hosting provider or domain registrar that you're using, so the exact steps for configuring DNS records may differ slightly from what's described here. However, the general process of translating DNS record information into web interface input fields should be similar across most interfaces.

Configure a domain for a web server

Let's start with the web server records:

A Record

An A record maps a domain name to an IP address. To configure an A record for your web server, you'll need to know the IP address of the server. Let's say your web server has an IP address of 192.0.2.1 and your domain name is example.com. To create an A record for the domain, you would add the following record in your DNS management interface:

example.com. IN A 192.0.2.1

This record maps the domain name "example.com" to the IP address 192.0.2.1.

CNAME Record

A CNAME record maps a domain name to another domain name (known as the canonical name). This is useful if you want to create a subdomain that points to the same IP address as your main domain. Let's say you want to create a subdomain called "www" that points to your web server. To create a CNAME record for the subdomain, you would add the following record in your DNS management interface:

www.example.com. IN CNAME example.com

This record maps the subdomain "www.example.com" to the domain name "example.com".

Configure a domain for email

Now let's move on to the mail server records:

MX Record

An MX record specifies the mail server(s) that should receive email messages for a domain. To configure an MX record for your mail server, you'll need to know the hostname of the server. Let's say your mail server has a hostname of mail.example.com and you want it to receive email messages for the domain example.com. To create an MX record for the domain, you would add the following record in your DNS management interface:

example.com. IN MX 10 mail.example.com

This record specifies that email messages for the domain example.com should be delivered to the mail server at the hostname mail.example.com with a priority of 10.

CNAME Record

A CNAME record can also be used for the mail server hostname, especially if you want to use a different hostname for the mail server than the one specified in the MX record. Let's say you want to use the hostname email.example.com instead of mail.example.com for your mail server. To create a CNAME record for the hostname, you would add the following record in your DNS management interface:

mail.example.com. IN CNAME email.example.com

This record maps the hostname "mail.example.com" to the hostname "email.example.com".

That's it! Once you have created these DNS records, your domain name should be properly configured to point to your web server and mail server. It may take some time for the changes to propagate across the internet, so be patient if it doesn't work immediately.

What's an NS record?

The NS record type, which stands for "name server," is a DNS resource record that specifies the authoritative name servers for a particular domain. The NS record type is used to delegate control of a subdomain to a different set of name servers, or to specify the authoritative name servers for the top-level domain itself.

The NS record type contains one or more name server hostnames, each of which ends with a period "." to indicate that it is an absolute domain name. For example, an NS record for the domain "example.com" might specify two name servers as follows:

example.com. IN NS ns1.example.com.
example.com. IN NS ns2.example.com.

In this example, the NS records delegate control of the "example.com" domain to the name servers at "ns1.example.com" and "ns2.example.com". These name servers are responsible for answering queries about any subdomains of "example.com", such as "www.example.com" or "mail.example.com".

It's worth noting that the NS record type is a fundamental component of the DNS system, and it plays a critical role in the resolution of domain names. When a DNS resolver receives a query for a domain name, it starts by querying the authoritative name servers for the domain specified in the NS record. These name servers can then provide the IP addresses of the web server or mail server associated with the domain.

DNS Record Types - The ones you need to know

There are several other DNS record types besides the NS record type, each of which serves a specific purpose. Here are some of the most commonly used DNS record types, along with a brief description of their purpose and examples of usage:

A Record

The A record type maps a domain name to an IPv4 address. An A record is typically used to point a domain name to a web server or other network device. Example usage:

example.com. IN A 192.0.2.1

This record maps the domain name "example.com" to the IPv4 address "192.0.2.1".

AAAA Record

The AAAA record type maps a domain name to an IPv6 address. An AAAA record is used in the same way as an A record, but for IPv6 addresses. Example usage:

example.com. IN AAAA 2001:db8:85a3::8a2e:370:7334

This record maps the domain name "example.com" to the IPv6 address "2001:db8:85a3::8a2e:370:7334".

CNAME Record

The CNAME record type maps one domain name to another domain name. A CNAME record is typically used to create an alias for a domain name or to point a subdomain to the main domain. Example usage:

www.example.com. IN CNAME example.com.

This record maps the subdomain "www.example.com" to the domain name "example.com".

MX Record

The MX record type specifies the mail servers responsible for handling email messages for a domain. An MX record is used to direct incoming email to the correct mail server. Example usage:

example.com. IN MX 10 mail.example.com.

This record specifies that mail for the domain "example.com" should be delivered to the mail server at "mail.example.com" with a priority of 10.

TXT Record

The TXT record type allows domain owners to add arbitrary text to their DNS records. TXT records are often used for security purposes, such as to verify domain ownership for email authentication or to publish cryptographic keys. Example usage:

example.com. IN TXT "v=spf1 a mx ~all"

This record publishes a Sender Policy Framework (SPF) record for the domain "example.com" to specify which hosts are allowed to send email on behalf of the domain.

SRV Record

The SRV record type specifies the location of a service, such as a SIP or XMPP server, for a domain. An SRV record is used to direct clients to the correct server for a specific service. Example usage:

_sip._tcp.example.com. IN SRV 10 60 5060 sipserver.example.com.

This record specifies that the SIP service for the domain "example.com" is provided by the server at "sipserver.example.com" on port 5060.

These are just a few examples of the many different types of DNS records that can be used to configure domain names. Each record type has specific configuration options and use cases, and it's important to choose the appropriate record type for your needs.

What is TTL in DNS?

TTL stands for "Time to Live" and it is a value in a DNS record that determines how long a resolver or caching server is allowed to cache the DNS information before it needs to refresh the information from the authoritative DNS server.

When a DNS resolver or caching server receives a DNS response, it stores the information in its cache so that it can quickly respond to future queries for the same domain name. The TTL value in the DNS record specifies how long the resolver should keep the cached information before it expires and the resolver must request updated information from the authoritative DNS server.

For example, if a DNS record has a TTL of 3600 seconds (1 hour), any resolver or caching server that receives the record will store it in its cache for up to 1 hour. During that time, any queries for the same domain name will be answered from the cache. After the TTL expires, the resolver or caching server will request updated information from the authoritative DNS server and update its cache with the new information.

TTL values can vary depending on the DNS record type and the domain name registrar or DNS hosting provider. In general, longer TTL values can reduce the load on the authoritative DNS server and improve DNS performance, but they can also lead to longer delays in propagating changes to DNS records.

It's important to set TTL values carefully when configuring DNS records to balance the need for fast response times with the need for timely updates when changes are made to DNS records.

The Domain Zone File

A zone file is a text file that contains all of the DNS resource records for a particular domain name or zone. The zone file is stored on the authoritative DNS server for the domain and is used to provide DNS resolution for the domain to the rest of the internet.

The zone file typically includes records for the domain name itself, as well as any subdomains or resource records associated with the domain. Each record in the zone file contains information such as the DNS record type, the value of the record, and the TTL for the record.

Here's an example of a simple zone file for the domain "example.com":

$ORIGIN example.com.
@  IN  SOA ns1.example.com. hostmaster.example.com. (
        2022040701 ; serial number
        7200       ; refresh
        3600       ; retry
        1209600    ; expire
        86400      ; TTL
      )
  IN  NS    ns1.example.com.
  IN  NS    ns2.example.com.
  IN  A     192.0.2.1
www IN  A     192.0.2.1
mail  IN  A     192.0.2.2

In this example, the zone file defines a few different types of records:

  • The SOA record specifies the Start of Authority for the zone and includes information such as the email address of the domain administrator, the serial number of the zone file, and the TTL for the zone.
  • The NS records specify the name servers responsible for the zone.
  • The A records specify the IPv4 addresses for the domain and its subdomains, such as "www" and "mail".

Each line in the zone file represents a single DNS resource record, and the records are typically arranged in a specific order that depends on the record type and the domain name. Zone files can be edited manually using a text editor, or they can be generated automatically by DNS management software.

Zone files are an essential component of the DNS system, as they provide the information that allows DNS resolvers and caching servers to resolve domain names to IP addresses.

How to find DNS info from command line (CLI)?

You can check for DNS records using the command line. Here are a few examples of commonly used commands and what they return:

nslookup

This command is used to query DNS servers to look up IP addresses and other DNS information. Here's an example query for the domain "nowintech.net":

nslookup nowintech.net

This command returns information about the DNS servers for the domain, as well as the IP address associated with the domain:

Server:  UnKnown
Address:  192.168.1.1

Non-authoritative answer:
Name:    nowintech.net
Address:  104.21.76.22
Name:    nowintech.net
Address:  172.67.153.79

dig

This command is another DNS lookup tool that provides more detailed information than nslookup. Here's an example query for the MX records of the domain "nowintech.net":

dig nowintech.net MX

This command returns the MX records for the domain:

; <<>> DiG 9.11.5-P4-5.1+deb10u5-Debian <<>> nowintech.net MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36877
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;nowintech.net.			IN	MX

;; ANSWER SECTION:
nowintech.net.		3600	IN	MX	10 mx.zoho.com.
nowintech.net.		3600	IN	MX	20 mx2.zoho.com.
nowintech.net.		3600	IN	MX	30 mx3.zoho.com.
nowintech.net.		3600	IN	MX	40 mx4.zoho.com.
nowintech.net.		3600	IN	MX	50 mx5.zoho.com.

;; Query time: 65 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Thu Apr 07 17:25:16 EDT 2022
;; MSG SIZE  rcvd: 150

Here's another example query for the CNAME record "cname" of the domain "nowintech.net":

dig cname.example.com CNAME

In this example, replace "cname.example.com" with the actual domain name that you want to query.

This command returns the CNAME record for the specified domain, which is typically an alias for another domain:

; <<>> DiG 9.16.15-Debian <<>> cname.example.com CNAME
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54594
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;cname.example.com.	IN	CNAME

;; ANSWER SECTION:
cname.example.com.	1800	IN	CNAME	alias.example.com.

;; Query time: 2 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Apr 07 17:25:16 EDT 2022
;; MSG SIZE  rcvd: 73

In this example, the CNAME record for "cname.example.com" points to the domain "alias.example.com".

host

This command is used to perform DNS lookups and query DNS servers for information about a domain name. Here's an example query for the A record of the domain "nowintech.net":

host nowintech.net

This command returns the IP address associated with the domain:

nowintech.net has address 104.21.76.22
nowintech.net has address 172.67.153.79
nowintech.net mail is handled by 10 mx.zoho.com.
nowintech.net mail is handled by 20 mx2.zoho.com.
nowintech.net mail is handled by 30 mx3.zoho.com.
nowintech.net mail is handled by 40 mx4.zoho.com.
nowintech.net mail is handled by 50 mx5.zoho.com.

 

Updated