You are here: Home > Networking

Advanced section on how hosting and DNS works

We did talk a little about the TLD (top level domain) in our intro section.
So in www.myname.com...
The TLD is .com
The 2nd level domain is myname
This is like a hierarchy that we have to go through.

DNS is the domain name system and name servers are important components in DNS.
A name server has a mapping between domain names and IP addresses. Not every nameserver will have the entire list of domain names - this would become a bottleneck and also force nameservers to have a humungous list of mappings. So instead there is a hierarchy - each nameserver will be responsible for a set of mappings. Whatever it is the authority for it would contain.

When someone tries to locate myname.com, the first step is to figure out the directory that has the servers for the .com domain.
So for that the DNS resolver (whatever we use to resolve the name) reaches out to a list of root servers. The root server gives a list of servers that have the records of .com domains. Next step is to reach out to one of these to find what servers have info about myname.com.
And the last step is go to the servers to get the IP address for myname.com
At every step including the last one there are always multiple servers that have the information so that we don't have a single point of failure.

An example


Let's take the domain: http://www.sparkcrews.com/
To look up details of any website we can lookup the WHOIS record (this has information that was used to register a domain). One place you are query for the WHOIS record for any website is at: https://whois.domaintools.com
We search here for sparkcrews.com and find the below:
Name Servers NS13.777SERVERS.COM (has 6,824 domains)
NS14.777SERVERS.COM (has 6,824 domains)

So sparkcrews.com has a specific server where it is hosted and the info about that is available in the above 2 nameservers. But when a client (we call this the DNS resolver) wants to get this info there needs to be a way for them to know that for sparkcrews.com they should reach out to ns13.777servers.com
How do they get to this? That's where the hierarchy helps.

In Linux there is a utility called dig which can be used to perform a DNS lookup; so  we'll execute this along with the 'trace' command for sparkcrews.com to figure out the list of queries that are made to resolve the domain name.
You can run this query online: https://www.digwebinterface.com/?hostnames=sparkcrews.com&type=&trace=on&ns=resolver&useresolver=8.8.4.4&nameservers=


.			85843	IN	NS	e.root-servers.net.
.			85843	IN	NS	h.root-servers.net.
.			85843	IN	NS	l.root-servers.net.
.			85843	IN	NS	i.root-servers.net.
.			85843	IN	NS	a.root-servers.net.
.			85843	IN	NS	d.root-servers.net.
.			85843	IN	NS	c.root-servers.net.
.			85843	IN	NS	b.root-servers.net.
.			85843	IN	NS	j.root-servers.net.
.			85843	IN	NS	k.root-servers.net.
.			85843	IN	NS	g.root-servers.net.
.			85843	IN	NS	m.root-servers.net.
.			85843	IN	NS	f.root-servers.net.
;; Received 228 bytes from 8.8.4.4#53(8.8.4.4) in 40 ms

com.			172800	IN	NS	a.gtld-servers.net.
com.			172800	IN	NS	b.gtld-servers.net.
com.			172800	IN	NS	c.gtld-servers.net.
com.			172800	IN	NS	d.gtld-servers.net.
com.			172800	IN	NS	e.gtld-servers.net.
com.			172800	IN	NS	f.gtld-servers.net.
com.			172800	IN	NS	g.gtld-servers.net.
com.			172800	IN	NS	h.gtld-servers.net.
com.			172800	IN	NS	i.gtld-servers.net.
com.			172800	IN	NS	j.gtld-servers.net.
com.			172800	IN	NS	k.gtld-servers.net.
com.			172800	IN	NS	l.gtld-servers.net.
com.			172800	IN	NS	m.gtld-servers.net.
;; Received 492 bytes from 192.58.128.30#53(192.58.128.30) in 52 ms

sparkcrews.com.		172800	IN	NS	ns13.777servers.com.
sparkcrews.com.		172800	IN	NS	ns14.777servers.com.
;; Received 113 bytes from 192.12.94.30#53(192.12.94.30) in 473 ms

sparkcrews.com.		14400	IN	A	103.14.122.124
sparkcrews.com.		86400	IN	NS	ns14.777servers.com.
sparkcrews.com.		86400	IN	NS	ns13.777servers.com.
;; Received 129 bytes from 103.14.123.121#53(103.14.123.121) in 231 ms
 
So the first line we see some server called 8.8.4.4 - that's Google's DNS server which is being used. So from here we get the list of root servers (the root servers are the ones that will have info about the TLD name servers).
That list of root-servers.net can be looked up here: https://www.iana.org/domains/root/servers
Next step is to get the servers having info about .com - in our case we got a reply for this from 192.58.128.30 (if you do a tracert command on your Windows/Linux box: tracert 192.58.128.30 then you will find that this IP maps to j.root-servers.net)
Again we have a bunch of servers that have the .com information. So he server e.gtld-servers.net (192.12.94.30) tells us that sparkcrews.com info is available in the nameservers ns13.777servers.com and ns14.777servers.com.
And the last reply that we got is from ns14.777servers.com where it says that sparkcrews.com is available at 103.14.122.124
You can verify this really is sparkcrews' IP by issuing a ping command.
  ping spakrcrews.com

DNS records - in the dig+trace output we see different record types; we have NS records and A records. The A record is the one that tells us what is the IP address we are looking for. But that "A" record came only from the last name server. Till then we only got NS records. So what are NS records? NS records tell us who is the authoritative name server. Ex: for sparkcrews.com it is ns13.777servers.com. For .com it is l.gtld-servers.net. and for the root server it is j.root-servers.net

Hosting and domain registration separate


Can we host our website with one company and register our domain name with another?
This is possible.
There are 2 parts to this.
1. Web hosting side - when signing up with a web hosting provider, as part of the setup they will ask you for your domain name. They will also provide you with 2 nameserver addresses (in our example this was ns14.777servers.com and ns13.777servers.com) which you need to provide in the DNS registration side.

2. Domain name registration side - over here you will be asked to provide 2 nameservers where your website can be located. The importance of this is that when someone does a DNS lookup this is what will say "for sparkcrews.com go to the NS ns14.777servers.com")
You may wonder "so what's the importance about the first step?"
The webhosting provider who is hosting the sparkcrews.com website will be hosting plenty of websites. The webhosting provider will have their DNS file which lists all the physical servers (IP addresses) and the domain names for the websites on their platform.
So now in NS ns14.777servers.com the entry saying that sparkcrews.com maps to 103.14.122.124 is created because of step 1.
And because of step 2 is why we have the mapping saying sparkcrews.com is on the NS ns14.777servers.com

In step 1 if we had done the setup saying our site name is sparkcrews.net then when someone searches for sparkcrews.com they will be led up to ns14.777servers but over there the record for sparkcrews.com will not be found (since we setup the site in the web hosting side as sparkcrews.net)