DNS, Domain Name System, is a hierarchical distributed naming system for computers, servers and every resource connected via internet. Since it was difficult to configure websites and servers DNS it is created to diagnose such problems by configuring access to different websites and understand what is going on. It has been in wide use since the 1980’s and it fundamental role is to translate domain names to IP addresses in order to be easily memorized by users.
It is basically used to translate computer hostnames into IP addresses. As an example, the www.example.com domain name will be translated to 220.127.116.11 (IPv4) and 2606:2800:220:6d: 26bf:1447:1097:aa7 (IPv6).
DNS name structure is shaped like a tree. The analogy of using the term tree leads to the use of several tree related terms while describing DNS.
- Root: is at the high level of the DNS name structure.
- Branch: is any contiguous portion of DNS hierarchy. It represents the domain and all the attached systems. And all of those branch are connected to the root
- Leaf: this is the end point of the structure. It can be a domain which hasn’t other domains underneath of it.
Domain name syntax:
Each domain name consists of one or several labels which are usually concatenated and delimited by dots. The right-most label conveys the top-level domain; for example, the domain name www.example.com belongs to the top-level domain com.
Their hierarchy are from right to left it means that each label will represent a sub domain or subdivision of the domain on the right. To more understand will use the same example of www.example.com here the “example” label is a subdomain of “com” domain and “www” is a subdomain of “example.com”.
A label may be composed by 63 characters and a domain may be composed by 253 characters. While using the DNS binary representation, the full domain name can’t exceed 255 octets. 255 octets of storage, since it also stores the length of the name.
Zone files are the locations where we save information. Each domain known by name servers will be stored in a zone file. The more name servers has zone files, the more requests will be answered authoritatively. Generally, we used zone file to just configure one domain. Some records may be found to define some resources are for the concerned domain.
By default, the zone’s $ORIGIN represents the highest level of authority. Taking the same example used in this article, if a zone was used to configure “example.com” domain so the $ORIGIN will be “example.com”
Moreover, the $TTL is a timer used to calculate the time to live of the provided information. Several questions would be answered by the caching name server using the queried results until the TTL runs out.
There is several types of records used. In the next section we will describe some of them.
It is a mandatory record used in all zone files. It should be the first existed record in a file besides it is the most complex to understand.
This record at the beginning is like the following:
domain.com. IN SOA ns1.domain.com. admin.domain.com. ( 12083 ; serial number 3h ; refresh interval 30m ; retry interval 3w ; exiry period 1h ; negative TTL )
We will explain each notion for you:
- The domain.com: is the root of the zone file. Often, you’ll see this replaced with @, which is just a placeholder that substitutes the contents of the $ORIGIN
- The IN SOA: “IN” is the beginning of the word Internet, and SOA indicates that there is a Star Authority record.
- domain.com defines the primary master name server for the concerning domain.
- domain.com represents the email address of the administrator of the concerned zone. As it is known there is a “@” missed here because it is replaced by just “.” But if we have another “.” In the name of the user so it will be replaced by “\”. It means that “[email protected] will be surname\name.domain.com)
- 12083: it is the serial number of the zone file. After each modification of the zone file this number must be incremented.
- 3h: it represents the refresh interval of the zone.
- 30m: it is the retry interval of the zone. After the refresh period, if the slave cannot connect to the master so it will wait this period to retry again.
- 3w: it is the expiry period.
- 1h: it is the time needed that the name server will cash a name error.
A and AAA records:
The A record is used to map a host to an IPv4 IP address while the AAA record is used to map a host to IPv6 IP addresses. Generally, it is represented like:
host IN A IPv4_address host IN AAAA IPv6_address
The record may be represented like this:
ns1 IN A 18.104.22.168
It is not important to give the full name, the host is sufficient.
ns1.domain.com. IN A 22.214.171.124
In most cases, this is where you define your web server as “www”:
www IN A 126.96.36.199
We should also give where the base domain is:
domain.com. IN A 188.8.131.52
We can also use the “@” to refer to the base domain:
@ IN A 184.108.40.206
We can also have an A name record defining the “server1” host and then we use the “www” as an alias for this host:
server1 IN A 220.127.116.11
www IN CNAME server1
Mostly, the same result could be achieved by using additional A or AAAA records.
They are used basically to define the mail exchanges within the domain. Unlike many other record types, mail records generally don’t map a host to something, because they apply to the entire zone. They usually look like this:
IN MX 10 mail.domain.com.
The MX record should generally point to a host defined by an A or AAAA record.
As example we consider that we have two mail servers:
IN MX 10 mail1.domain.com. IN MX 50 mail2.domain.com. mail1 IN A 18.104.22.168 mail2 IN A 22.214.171.124
This record type defines the name servers that are used within the concerning zone. In general, they look like this:
IN NS ns1.domain.com. IN NS ns2.domain.com.
You should have at least two name servers defined in each zone file. If there is a problem with one server. Most DNS server software considers a zone file to be invalid if there is only a single name server.
Usually, include the mapping for the hosts with A or AAAA records:
IN NS ns1.domain.com. IN NS ns2.domain.com. ns1 IN A 126.96.36.199 s2 IN A 188.8.131.52
There are quite a few other record types you can use, but these are probably the most common used records.
The given information is as first step enough for you to start working with DNS. As we said there are other records don’t mentioned above, DNS is a known tool and has many benefits.