Interviewer: What is the DNS protocol? Can you describe the complete DNS query process?

Interviewer: What is the DNS protocol? Can you describe the complete DNS query process?

[[400343]]

This article is reprinted from the WeChat public account "JS Daily Question", the author is Huihui. Please contact the JS Daily Question public account to reprint this article.

1. What is

DNS (Domain Names System) is an Internet service that converts domain names and their corresponding IP addresses.

Simply put, DNS is equivalent to a translator, responsible for translating domain names into IP addresses.

  • IP address: A long string of numbers that uniquely identifies a computer on a network.
  • Domain name: It is the name of a computer or computer group on the Internet, consisting of a string of names separated by dots, used to locate the computer during data transmission.

2. Domain Name

A domain name is a hierarchical structure, from top to bottom, it is the root domain name, top-level domain name, second-level domain name, third-level domain name...

For example, www.xxx.com, www is the third-level domain name, xxx is the second-level domain name, and com is the top-level domain name. The system has made compatibility for users, and the root domain name at the end of the domain name generally does not need to be entered.

There is a domain name server at each level of the domain name, as shown below:

In addition, there is the computer's default local domain name server

3. Query method

There are two ways to query DNS:

  • Recursive query: If A requests B, then B, as the recipient of the request, must give A the answer he wants.

Iterative query: If receiver B does not have the exact content that requester A needs, receiver B will tell requester A how to obtain the content, but will not make the request itself.

4. Domain name cache

When the domain name server is resolving, use the cache to save the mapping between the domain name and the IP address

The DNS records in the computer are also divided into two cache modes:

  • Browser cache: After obtaining the actual IP address of the website domain name, the browser will cache it to reduce the loss of network requests.
  • Operating system cache: The operating system cache is actually the hosts file configured by the user

5. Query process

The process of resolving a domain name is as follows:

  • First, search the browser's DNS cache, which maintains a table of domain name and IP address correspondence
  • If there is no hit, continue searching the operating system's DNS cache
  • If there is still no hit, the operating system sends the domain name to the local domain name server, which uses recursive query to query its own DNS cache and returns the result if the search is successful.
  • If the DNS cache of the local domain name server does not hit, the local domain name server will iteratively query the superior domain name server.
    • First, the local domain name server sends a request to the root domain name server, and the root domain name server returns the address of the top-level domain name server to the local server.
    • After the local domain name server obtains the address of the top-level domain name server, it initiates a request to obtain the address of the authority domain name server.
    • The local domain name server initiates a request to the authority domain name server based on its address, and finally obtains the IP address corresponding to the domain name.
  • The local domain name server returns the obtained IP address to the operating system and caches the IP address itself.
  • The operating system returns the IP address to the browser and caches the IP address itself.
  • At this point, the browser has obtained the IP address corresponding to the domain name and cached the IP address.

The process is shown in the figure below:

References

https://zh.wikipedia.org/wiki/%E5%9F%9F%E5%90%8D%E7%B3%BB%E7%BB%9F

https://www.cnblogs.com/jmilkfan-fanguiju/p/12789677.html

https://segmentfault.com/a/1190000039039275

https://vue3js.cn/interview

<<:  Free and easy to use! This data recovery software found my video from two years ago

>>:  China Mobile launches A-share listing: "Making money" but not "cutting leeks"

Recommend

What is Wi-Fi-6E and how is it different from Wi-Fi-6

Three years ago, Wi-Fi 6 technology entered the m...

Enterprise 5G: A guide to planning, architecture and benefits

Enterprise 5G deployments require extensive plann...

SmartHost adds block storage (large hard drive VPS), 256GB for only $1

The day before yesterday, I received an email fro...

The struggle between operators and users: Who decides my package?

What service do you like the most? The most likel...

What exactly is semantic communication?

As we all know, since the outbreak of the informa...

What factors determine the price of HTTPS certificates?

In the era of big data, when information is trans...

Eleven things to note when using natural cooling technology in data centers

The Green Grid, a non-profit organization dedicat...

RAKsmart Hong Kong VPS simple test, three network direct connection/Telecom CN2

A few days ago, we shared information about RAKsm...