How does browser knows where website exists?
A answer to this question is pretty simple and yet complicated at the same time . So long story short it is with the help of DNS. If you have earlier read my blogs you must have understood that I always introduce why what how aspects in my article so you need not worry just lay back and peacefully read the article.
First things first …
What is DNS?
Domain name system server (abbreviated as DNS) in simpler terms is a phonebook of internet that translates human-readable domain names to numerical ip address. Inorder to crack interview this won’t sufficient right? So here we go. . Domain Name System is a hirerachial and distributed naming system that translates human readable domain names to numerical or machine readable ip addresses. DNS helps with the following aspects -
Eliminates the need to remember ip addresses.
It supports caching and improves retrieval speed.
It uses TLD,authorative DNS server and root server.
Converts human-readable address into (let’s say I am taking geeksforgeeks here for reference ) ip address.
There are four DNS servers involved in loading a website:-
DNS Recursor :- Now DNS recursor is more like a librarian who is asked a particular book from library. This is specifically designed to recieve queries from client machines in the form of browsers . Basically it helps in DNS query made by client by creating additional request.
root name server:- Root name server is a destination where human readable host names are translated into IP addresses. It acts like key in a hashmap that helps in retrieving value from the table.
Top level Domain (TLD):- The top level domain server (TLD) can be thought of as a specific rack of books in a library. This nameserver is the next step in the search for a specific IP address, and it hosts the last portion of a hostname (In geeksforgeeks.org the TLD server is “org”).
Authoritative nameserver - This final nameserver can be thought of as a dictionary on a rack of books, in which a specific name can be translated into its definition. The authoritative nameserver is the last stop in the nameserver query. If the authoritative name server has access to the requested record, it will return the IP address for the requested hostname back to the DNS Recursor (the librarian) that made the initial request.
Steps in DNS Lookup
The 8 steps in a DNS lookup:
A user types ‘example.com’ into a web browser and the query travels into the Internet and is received by a DNS recursive resolver.
The resolver then queries a DNS root nameserver (.).
The root server then responds to the resolver with the address of a Top Level Domain (TLD) DNS server (such as .com or .net), which stores the information for its domains. When searching for example.com, our request is pointed toward the .com TLD.
The resolver then makes a request to the .com TLD.
The TLD server then responds with the IP address of the domain’s nameserver, example.com.
Lastly, the recursive resolver sends a query to the domain’s nameserver.
The IP address for example.com is then returned to the resolver from the nameserver.
The DNS resolver then responds to the web browser with the IP address of the domain requested initially.
Once the 8 steps of the DNS lookup have returned the IP address for example.com, the browser is able to make the request for the web page:
The browser makes a HTTP request to the IP address.
The server at that IP returns the webpage to be rendered in the browser (step 10).

Diagram - DNS Lookup
Dns Records
A records : A in A record stands for address and this is the most fundamental type in DNS record : it indicates IP address of a given domain. For example, if you pull the DNS records of geekforgeek.org, the A record currently returns an IP address of: 104.17.210.9. A record in most of the cases is the last record from where we can retrieve IP address of host name. A record specifically works for ipv4 address.
AAAA record : AAAA record specifically works for all ipv6 addresses where A record doesn’t comes into picture.
CNAME record : A "canonical name" (CNAME) record points from an alias domain to a "canonical" domain. A CNAME record is used in lieu of an A record, when a domain or subdomain is an alias of another domain. All CNAME records must point to a domain, never to an IP address. Imagine a scavenger hunt where each clue points to another clue, and the final clue points to the treasure. A domain with a CNAME record is like a clue that can point you to another clue (another domain with a CNAME record) or to the treasure (a domain with an A record).
For example, suppose blog.example.com has a CNAME record with a value of "swayam.geeksforgeeks.org" (without the "swayam"). This means when a DNS server hits the DNS records for blog.example.com, it actually triggers another DNS lookup to example.com, returning example.com’s IP address via its A record. In this case we would say that example.com is the canonical name (or true name) of swayam.geeksforgeeks.org.
MX record: A DNS 'mail exchange' (MX) record directs email to a mail server. The MX record indicates how email messages should be routed in accordance with the Simple Mail Transfer Protocol (SMTP,the standard protocol for all email).

The 'priority' numbers before the domains for these MX records indicate preference; the lower 'priority' value is preferred. The server will always try mailhost1 first because 10 is lower than 20. In the result of a message send failure, the server will default to mailhost2.
The email service could also configure this MX record so that both servers have equal priority and receive an equal amount of mail:

TXT record: The DNS ‘text’ (TXT) record lets a domain administrator enter text into the Domain Name System (DNS). Text is stored in the form of one or more strings within quotation marks. The TXT record was originally intended as a place for human-readable notes. However, now it is also possible to put some machine-readable data into TXT records. One domain can have many TXT records.
Example of a TXT record:
| geekforgeek.org | record type: | value: | TTL |
| @ | TXT | "This is an awesome domain! Definitely not spammy." | 32600 |
NS record:NS stands for ‘nameserver,’ and the nameserver record indicates which DNS server is authoritative for that domain (i.e. which server contains the actual DNS records). Basically, NS records tell the Internet where to go to find out a domain's IP address. A domain often has multiple NS records which can indicate primary and secondary nameservers for that domain. Without properly configured NS records, users will be unable to load a website or application.
A nameserver is a type of DNS server. It is the server that stores all DNS records for a domain, including A records, MX records, or CNAME records.
Almost all domains rely on multiple nameservers to increase reliability: if one nameserver goes down or is unavailable, DNS queries can go to another one. Typically there is one primary nameserver and several secondary nameservers, which store exact copies of the DNS records in the primary server. Updating the primary nameserver will trigger an update of the secondary nameservers as well.
When multiple nameservers are used (as in most cases), NS records should list more than one server.