The DNS (Domain Name System) is the backbone of the Internet.
The big trick behind the DNS is a that it’s a distributed database. This allows it for every owner of a Domain to manage their own part of the DNS (their own domain).
You may already know that the DNS maps IP addresses to hostnames. For example the page where you are looking at now is on a webserver which is installed on a machine with an IP Address of 22.214.171.124 and it has the hostname ewagenaar.com. The mapping allows Internet client software to easily connect to the host just by entering it’s name. Why is the IP address important? Computers don’t understand names, in a Computer network the machines can only connect to each other by using the numerical IP addresses which we see as a series of numbers, separated by dots.
To understand Subdomains we first need to know about the Topdomain (or TLD, Top Level Domain). In the case of ejwagenaar.com the TLD is ejwagenaar.com and I since I am the owner of this domain, can do anything I want with it, like for example adding an FTP server. To do this I can change the zone file of my domain and add an entry ftp.ejwagenaar.com. In the same way I could add a mailserver (mail.ejwagenaar.com) or a webserver (www.ejwagenaar.com). In reality the webserver already exist. You can check it out by going to https://evertwagenaar.com/ and https://evertwagenaar.com/As you can see they both do the same thing; Opening my website at the homepage.
I’m not limited to this. I can also add Servers like FTP (ftp.ejwagenaar.com), an SMTP server (mail.ejwagenaar.com) or a game server (games.ejwagenaar.com). I can even create sub-sub domains: (zimba.mail.ejwagenaar.com) or if you want your own Subdomain under my domain johndoe.ejwagenaar.com, which you then are responsible for and create an unlimited amount of hosts for. This would require me to setup my own DNS. To comply with this I would have to add the DNS(es) to my domain. These would be ns1.ejwagenaar.com and ns2.ejwagenaar.com. At present these don’t exist yet because there’s no need for doing this.
As you see the DNS is a hierarchical system. Considering of Domains and Subdomains. What is the Top Level Domain of my own Domain ejwagenaar.com? It is the ‘.com’ TLD and it is managed by the DNS root servers.
The nice thing about this is that you only need one single DNS to find all names on the Internet. How does this work?
As we already saw, all Domains are connected with each other trough an hyrarchic system where each domain has it’s own Domain Name Server which is authorized to hold it’s own zone (the list of all hosts and their IP-Addresses. We say that the DNS is authorities for it’s own records. You can see this when you use the program nslookup. This is a command line tool and comes standard with Windows, MacOS and Linux. It allows you to query DNS servers.
When you query a DNS server for names in it’s own zone it will list the output with ‘A’ characters in front of the hostnames and IP-Addresses.
To make Domain lookups faster, Domains and Subdomains can exchange their data. In DNS termology this is know as zone transfer.
How does a lookup work?
The name lookup works recursive. It starts at the Top Level Domain (TLD). In my case this is the ‘.com’ domain, which has its DNS servers in the root Domain Servers. Here the ‘Authorative’ DNS server for ejwagenaar.com is looked up and the request is forwarded to that DNS. The DNS gives an ‘A’-reply and the name is resolved.
You probably can imagine that this process takes a lot of time to complete. In reality it usually takes only a few milliseconds. This is accomplished by the zone transfers together with a smart caching system.