DNS (Domain Name System), or Domain Name System, is a distributed naming system used to translate domain names into IP addresses. It acts as the “phone book” of the internet, converting human-readable domain names into computer-understandable IP addresses. Today, Old Fish will discuss the working principles of DNS with you.
Classification of Domain Name Servers #
The DNS system consists of multiple levels of domain name servers, each responsible for managing domain names and IP address mappings within a specific zone. These servers mainly include:
-
Root Name Servers: Located at the highest level of the DNS hierarchy, there are 13 root name servers with different IP addresses distributed globally. They store information about top-level domain name servers and are responsible for managing the IP addresses of domain name servers for top-level domains (such as .com, .org, .net, etc.).
-
Top-Level Domain (TLD) Name Servers: Responsible for managing the mapping of domain names and their subdomains under specific top-level domains (such as .com, .org, .net, etc.). For example, the .com TLD name server stores the mapping information for all domain names ending with .com.
-
Authoritative Name Servers: The “official” name servers for each specific domain, storing the mapping information between that domain name and its IP address. When a local name server needs to resolve a specific domain name, it sends a query request to the authoritative name server for that domain.
-
Local Name Servers (Recursive Resolvers): Located within the user’s local network, usually provided by the Internet Service Provider (ISP). When a user initiates a domain name query request, the local name server is contacted first. If the local name server has already cached the corresponding mapping information, it will directly return the result; otherwise, it will initiate queries to the root name servers, TLD name servers, and authoritative name servers through recursive or iterative queries based on the hierarchical structure of the queried domain name to obtain the required mapping information.
DNS Domain Name Resolution Process #
The DNS domain name resolution process includes two methods: recursive query and iterative query. However, local name servers usually try recursive queries first, and if resolution fails, they switch to iterative queries. The following are the detailed steps of the DNS domain name resolution process:
-
Local Query: When a user enters a domain name in a browser, the browser sends a domain name resolution request to the local DNS server. The local DNS server first checks its cache for the corresponding IP address. If it is in the cache, the IP address is returned directly; if it is not in the cache, the process proceeds to the next step.
-
Recursive Query (or Iterative Query):
Recursive Query
: The local name server sends a query request to a root name server. The root name server returns the IP address of the TLD name server based on the requested domain name information. The local name server then sends a request to the TLD name server to obtain the IP address of the next-level domain name server, and this process continues level by level until the corresponding IP address is found. Throughout this process, the local name server is responsible for forwarding the query requests level by level and waiting for the final result to be returned.
Iterative Query
: In an iterative query, the local name server queries upwards level by level and then downwards level by level. It first initiates a query request to a root name server, which replies with the IP address of a TLD name server. The local name server then initiates a new query request to the TLD name server, which replies with the IP address of an authoritative name server. The local name server continues to send a query request to the authoritative name server, eventually obtaining the IP address corresponding to the domain name. Throughout this process, the local name server needs to handle the responses from each level of query itself and query downwards level by level until it obtains the required IP address.
-
Query Result Return: Once the local name server obtains the IP address corresponding to the domain name, it saves this result in its cache (so that it can directly return the result for the next query, improving query speed) and returns the result to the user’s browser.
-
Establish Connection: After receiving the IP address, the browser sends an HTTP request to that IP address, establishes a connection with the server, and retrieves the webpage content.
Other Functions of DNS #
In addition to the basic domain name resolution function, DNS also supports some other functions, such as:
-
Load Balancing: DNS can resolve a domain name to multiple IP addresses, achieving load balancing and improving website availability and performance.
-
Reverse DNS Lookup: Resolving an IP address to a domain name, used in areas such as network security and log analysis.
-
Failover: When a server fails, DNS can resolve the domain name to other normal servers, achieving failover and disaster recovery backup.
Conclusion #
In summary, the working principle of DNS is to achieve domain name resolution by mapping domain names to IP addresses. It uses a hierarchical, distributed structure to manage the mapping relationship between domain names and IP addresses, and through recursive and iterative queries, it makes it easy to use human-readable domain names to access various network resources on the internet.