This post explains how to point your domain name to a server by writing a plain text file.
What is a zone?
To setup a website, you need a domain name and a server hosting your web. The glue that associates your domain name with the IP of your server is the DNS zone. The DNS zone is a text file with at least a line like this:
@ 3600 IN A 188.8.131.52
This means “the IP of this domain is 184.108.40.206. Reload this file in hour to check for changes”. This file is physically hosted in the nameserver of your domain seller, which together with other nameservers forms the Domain Name System.
Usually you would configure this file through a web interface but writing it yourself in plain text is straightforward. Here is my complete zone file:
* 3600 IN A 220.127.116.11 @ 3600 IN A 18.104.22.168 @ 3600 IN MX 1 ASPMX.L.GOOGLE.COM. @ 3600 IN MX 5 ALT1.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 5 ALT2.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 10 ALT3.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 10 ALT4.ASPMX.L.GOOGLE.COM. @ 3600 IN TXT "google-site-verification=H2wZIxEo74Ygq1_mcoj4k1M9UUY8cJahCgvt0-7aWEE"
It looks complicated now, but everything looks complicated before it looks easy. By the end of this post you will know how to write yours.
What is the DNS?
The Domain Name System (DNS) is a globally distributed network of name servers that translate domain names to IP addresses.
A name server is a server which answers DNS queries. When you buy a domain, the seller sets up your domain on one of his name servers, and gives you access in case you want to change anything. Whenever a browser requests the IP for your domain, that name server will reply with the information.
The DNS is hierarchical. Usually, big servers provided by your Internet provider company have most popular domains in memory. If they are queried about a new domain, they delegate and delegate until reaching the original name server where that domain was registered. If you change your DNS data, it will take between 1 and 10 hours to spread around the world, up to a maximum of around 36 hours.
The DNS information for a given domain is contained in a zone file, which is a file containing rows with the following fields:
|name||TTL||record class||record type||record data|
The name indicates the subdomain that this record refers to. The value may be @ (base domain), * (any subdomain), or an arbitrary string (a specific subdomain).
|blog||blog.pokemon.com||Subdomains are defined by any arbitrary string in the field name.|
|@||pokemon.com||This is the same as blank, but other records may reference this entry using @.|
|*||*.pokemon.com||An asterisk means this record applies to any subdomain not explicitly named in the zone.|
TTL is the numerical value, in seconds, of how long a DNS record will be kept in memory before it is read again from the zone file. This implies that if you edit the zone file, that change will take up to TTL seconds to be effective. Common values seems to be 10800 (3 hours), and 28800 (8 hours).
The record class is IN (short for Internet) for records involving host names, servers, or IP addresses.
The record type is one of 38 possible DNS record types. The most common are A, AAAA, CNAME, MX, TXT.
The record data depends on the kind of record.
- For an A record it will be an IP address.
- For a MX record it will be: priority, space, MTA name, dot.
- For a TXT the value format is not defined in the DNS standard.
So what was in my zone file?
@ 3600 IN A 22.214.171.124
This is an A record for the IP of my virtual machine. It has no subdomain so it refers to my base domain jano.com.es. The name server will re-read the file every hour (3600 seconds).
* 3600 IN A 126.96.36.199
This maps any subdomain to the same IP. You could be browsing this site using asfhsdkfjdsh.jano.com.es and it would work just the same. Try it. If I wanted to create just an specific subdomain like blog, I would replace the asterisk with it.
@ 3600 IN MX 1 ASPMX.L.GOOGLE.COM. @ 3600 IN MX 5 ALT1.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 5 ALT2.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 10 ALT3.ASPMX.L.GOOGLE.COM. @ 3600 IN MX 10 ALT4.ASPMX.L.GOOGLE.COM.
These are the MX records of the Gmail servers. The decimal number after the MX indicates the priority of each server (which one you should query first). In MX records, the domain name always ends with a dot.
@ 3600 IN TXT "google-site-verification=H2wZIxEo74Ygq1_mcoj4k1M9UUY8cJahCgvt0-7aWEE"
Finally, this is a TXT record that verifies my ownership of jano.com.es for Google. Some sites like Google, give you a string and ask you to create a TXT record with it to prove that you own that domain.
There are three tools to read DNS records: dig, host, and nslookup. If you are using MacOS or Linux, you may have all three. On Windows, you have only nslookup.
Try checking the TXT record of my domain:
dig -t txt jano.com.es host -t txt jano.com.es nslookup -type=TXT jano.com.es
There is a lot to learn about the DNS if you are so inclined.