Am gonna tell u the plain old topic of what DNS is.
Every computer/server/machine etc needs to have
a name or id or something unique, so that it can be reached by anyother computer/server/machine over the internet.
IP address is the one which solves this problem, so every computer in this world has either an internal IP/External IP
so in order to communicate between one computer to another u just needs to specify its IP(sender or receiver).
For eg: if u want to communicate to google's computer, enter its ip, facebook, youtube, yahoo etcc all are same. but how dumbsters(like me) can able to remember all those computer's IP addresses, thats y some vice
people introduces something called DNS, DNS is basically a hashmap that stores english words with IP address. something like below;
On a highlevel, this explains on what is DNS and why do we need them.
Basic structure of DNS:
www.example.com => in this www is subdomain example is main domain (the one that u purchase)
com is TLD(Top Level Domain).
com, xyz, biz etc all comes under TLD's.
There are several entities or things that u need to know before jumping into really how this resolves.
- DNS resolver.
- Root Server.
- TLD Domain Server.
- Autoritative Name Server.
DNS resolver : Consider this a computer/server can be ur router/ISP's_router/google's resolver(8.8.8.8) etcc,
this will basically takes ur domain and asks the root server which root server got the information for
the tld of the domain.
for eg: if you query www.example.com it will ask for com tld, if u query for www.example.xyz, it will ask
for xyz, to the root servers.
Now u may have a question, how does DNS resolver knows the IP of root servers, coz if it doesn't knows
then root server domain name again needs to be resolved right(which can't be the case). so basically
there are only 13 IP's in this planet(this 13 ip may be 1k or even 10k of servers, not sure),
so every DNS resolver will have this 13 root servers IP configured as constants in their machines/computers/server etc.
NOTE: DNS resolver can be ur router/ISP router, also everytime u(browser or app etc)
request a ip address for domain, it will cache in router layer(even os) for next use for some time(TTL).
Root Server : Root server will basically gives u the list of servers(with IP address) to DNS resolver, it has all the TLD records and it is maintained by ICANN.
TLD Server : TLD Server will give u the authoritative server(the nameserver that ur domain lives),
How TLD server will know our domain IP ?
Whenever u buy any domain, for eg: you are buying xxx.com(SFW domain) from namecheap(registrar),
after succesful buying, the namecheap default nameservers(authoritative server) will be make some API call
request to registry, which inturn update the TLD servers and update the records.
In some cases u will configure other nameservers in ur registrar, for eg: u may configure cloudflare nameservers
in namecheap, then in that case, for ur domain cloudflare nameservers will be pushed to TLD servers.
Authoritative name Server : This gives ur final IP address for ur domain.
Below is a simple snippet of DNS server(without recursion).