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

China's 4G speed compared to the United States: the gap is amazing

In 2016, the number of China Mobile's 4G user...

The Secret of Online Physical Examination Technology (Part 1)

1. Necessity of online physical examination In da...

Why is 5G suddenly not popular anymore?

In the past two days, an article about the curren...

HOSTEROID: €2.1/month KVM-512MB/10GB/324GB/Vienna & New Jersey & London

HOSTEROID is a foreign hosting company founded in...

How to connect multiple Ethernet switches?

Ethernet is not a new technology as it has been u...

Pre-terminated trunk copper cable and method of using the same

High-density cabling products and standard modula...

Huaxia Finance: Create an investment product that makes young people addicted

[51CTO.com original article] If someone asked wha...

Unveiling the mystery of MPLS, do you know all this?

Before formally learning MPLS, let us review the ...