Introduction - What is DNS?
The acronym DNS stands for Domain Name System. It is the backbone of internet. Its purpose is to resolve the hostnames that you input into your browsers search bar (e.g. domain.com) and finds their internet address(IP of their location), otherwise no communication can be established, since IP addresses are the main way that data is transferred over the internet.
For example if you type example.com it will go ask the authoritative DNS server for the top level domain ‘.com’ and fetch example.com’s host server name servers which in terms will eventually lead you to the IP address at which example.com resides(we say eventually because the name servers of that server might point at another server’s name servers).
All those details that we mentioned in the example above – name servers and IP addresses are stored in the host server’s DNS zone file. The information that is stored in a DNS zone file is defined by DNS records in a text format.
A DNS record is a text entry in the host server’s DNS file that presents information to the DNS resolver about various kind of data. The format in which a DNS record is noted is the following:
<owner of the record> <time to live> <record class><record type> <record specific data>
The owner of the record is the domain name for which the record is relevant. If this field is left blank it will by default assume the value of this field for the previous record.
The time to live, abbreviated as TTL, present’s the domain name client with a time variable(in seconds) for which the data of the given record is relevant, so that it can be stored in the client’s cache for faster access. Once the time expires the user discards the old information and makes a request to the server for new data.
The record class informs of the namespace for which the given record information is intended. The most commonly used one is the IN namespace which stands for internet. But there are other namespace types as well, but we won’t go into further detail.
The record type is the field that informs of the functionality of the given record. It also gives the name of the whole record.
Record specific data – one or several fields of data that is specific for each record type.
Example of a DNS record entry in the zone file:
this.example.com. 17700 IN A 18.104.22.168
This example shows that the domain this.example.com is located on the IP 22.214.171.124. And the time to live for the record is 17700. Also not that the domain provided in the owner field end with a dot, this is important in DNS records, since if there isn’t a dot the hostname to which the IP will resolve is this.example.com.example.com.
We’ll review the record type in more detail in the next section of this tutorial.
A and AAAA records have similar purpose in the DNS zone file. The A record (also called address record) assigns and IP address to a domain or subdomain, the IP that is stored is in the IPv4 format. AAAA record does the same as the A record, but it stores IPv6 addresses.
The name of the AAAA record derives from the fact that IPv6 addresses require 128 bits to store an address, in contrast to IPv4’s 32 bits, which is 4 times greater thus the 4 A’s.
Example for A record:
example.com. 17700 IN A 126.96.36.199
This example states that the domain example.com’s IP is 188.8.131.52, this data will expire for the DNS sever client’s cache after 17700 seconds.
Example for AAAA record:
example.com. 25700 IN AAAA FE80::0202:B3FF:FE1E:8329
This record states the same as the previous example only this time example.com resolves to FE80::0202:B3FF:FE1E:8329 the record class is again Internet, and the time after which this data expires in the cache is 25700 seconds.
CNAME Records (also known as canonical name records) shows that the specified domain name is an alias of the domain that is presented in the <record specific data> field. An example would be if you wish to make so that regardless of the subdomain that the user enters, the server will always resolve to your primary domain:
*.mypriamrydomain.com. 27500 IN CNAME mypriamrydomain.com.
The example above is a common convention which is applied in order to make so that even if, for example, the user inputs a wrong amount of w’s - e.g. ww. mypriamrydomain.com it will still resolve. This is achieved by the wildcard notation that we won’t discuss in this tutorial. The other usage of this is for wildcard subdomains, for ease of the owner of the website, so that he mustn’t input a new record for each subdomain that is created.
The MX record is used to specify a mail server. It then points to an A record which resolves to the correct IP address for the mail server. In the data specific field you must also specify a priority of the mail server, this convention is necessary If you specify multiple MX record entries In the zone file. The priority indicates which server should be used first if there is a mailing task to be handled, if that sever is unavailable the next one in the priority list will be used instead. The priority dictated by a numeric value where the lower the number the higher the priority, with the highest priority being 0.
example.com. 17100 IN MX 0 mailserver.com.
The example above specifies that emails sent to mail.example.come should be resolved to the mail server located at mailserver.com. Keep in mind that you must also specify an A record (or AAAA record) pointing to the mail server’s IP location.
The pointer record is used to point an IP to a selected host name. PTR records are primarily used for reverse DNS lookup (obtaining a host name via the IP that resolves to that hostname. You should ask your hosting provider regarding details related with setting up a PTR record.
A NS record or (name server record) tells recursive nameservers which name servers areauthoritative for a zone. Recursive nameservers look at the NS records to work out who to ask next when resolving a name.
domain.com. 28500 IN NS ns1.domain.com.
The start of authority record is absolutely necessary for a DNS zone file. Its purpose is provide information about the server, such as the authoritative master name server for the zone file, an email address of the server’s administrator. The SOA record also contains a parameter that contains the domainID and timers which give out information about the expiration of the zone file, update period timer. An important fact is that only one SOA record may exist in a zone file.
domain.com. 17500 IN SOA ns.domain.com. user.domain.com. ( 5002130210 2d 1h 2w 1h )
The example above gives the following information:
ns.domain.com is the master name sever for domain.com’s zone file
User.domain.com is the email to the name server’s administrator
( 5002130210 2d 1h 2w 1h ) – the informative parameter containing the domain id, and two time parameter indicating the expiration time of the zone file, and the last time that an update was made.
SRV records give information about available services on your system. Usually they are used together with SIP configuration. Particularly SRV records have a specific notation for specifying the name of the owner domain. It is constructed in this way:
_<name of service>._<protocol name>.domain.com
The parameters that must be set in the record specific data field:
1. Host of the specified service – a domain name must be input
2. a priority integer - works in the same way as the MX priority parameter
3. weight - used to distribute the load that can be accumulated on any of the servers that are being used(it is indicated by an integer and the lowest amount of load that can be set is 0)
4. port on which to connect in order to obtain the desired feature.
Example of an SRV record:
_http._tcp.domain.com. 17500 IN SRV 0 3 80 example.com.
The provided functionality is http, the protocol is tcp, and the 3 numbers in the record specific data field are priority=0, weight=3 and port = 80, after which is the host’s name – example.com.
Text records are used to store any information in a txt format on the zone file. Frequently the TXT record is used to store information such as domain keys and Domain Keys Indentified by e-mail. In some occasions there might be a txt record containing information about the servers network, datacenter and other types of administrative information. In the more frequent cases it is used to store sender policy framework (SPF) specifications.
Example of a txt record that is storing SPF details:
domain.com. 75000 IN TXT “v-spf1 –all’
Allows the use of regular expression based rewriting for domain names, in order to use them as URI’s.
These records are usually used along with SIP (session initiation protocol), in order to root telephony sessions over IP networks.