Understanding DNS: A Guide to Domain Name System Basics
I came across an educational post about DNS on the Upyun Cloud official WeChat account and found it quite useful, so I decided to repost it. Based on my understanding of the article, I drew a simple flowchart.

The flowchart was created using Processon. Below is the original article text, with some modifications.
Have you ever encountered a situation while browsing the internet where QQ messages are sent normally, but web pages fail to load, even though your network connection appears normal? Many people feel at a loss in such situations. How should you handle this, and what is actually happening?
A quick search reveals that computers usually automatically obtain DNS server settings and do not require manual configuration. However, in special cases where the DNS server is not obtained or the server fails, we need to manually change the DNS to ensure normal web access. Such display failures are often caused by incorrect DNS configuration and can be resolved by modifying the DNS settings.
So, where is DNS located, and how do we modify it?
What is DNS?
DNS (Domain Name System) is an abbreviation for the Domain Name System. It is one of the foundations of the Internet, used to map domain names to IP addresses, much like a phone book in a mobile phone that maps people's names to phone numbers. When we enter a web address in a browser, DNS queries convert it into the corresponding server's IP address. Without DNS, we would need to remember the IP address of every site to access it.

In the early days of the Internet, this was relatively easy to do. People could easily map specific IP addresses to specific computers and access websites by directly entering specific IP addresses in the browser. Later, as more devices and people joined this evolving network, the number of IPs increased, making memory a huge burden. Netizens wanted addresses composed of easier-to-remember words, leading to the birth of domain names.
In the 1970s and early 1980s, these names and addresses were assigned by a single person (Elizabeth Feinler from Stanford University), who maintained a master list of all computers connected to the Internet in a text file called HOSTS.TXT.
Obviously, as the Internet developed, this situation was unsustainable. Too many addresses could not be maintained by one person. Therefore, in 1983, researcher Paul Mockapetris from the University of Southern California developed the initial Domain Name System and named it DNS. Although DNS has changed significantly since then, its fundamental working principle remains the same as it was 40 years ago.
Before diving into the role and working principle of DNS in the network, let's first look at the categories of DNS.
DNS Server Categories
All DNS servers fall into one of the following four categories: recursive resolvers, root name servers, TLD (Top Level Domain) name servers, and authoritative name servers. In a typical DNS lookup, these four types of DNS servers work together to provide the client with the IP address of the specified domain.
DNS Recursive Resolver
The recursive resolver (also known as a DNS resolver) is the first stop in a DNS query. It acts as an intermediary between the client and the DNS domain server. Upon receiving a DNS query request from a web client, the recursive resolver will respond using cached data, or send a request to the root name server, then to the TLD name server, and finally to the authoritative name server. After receiving a response from the authoritative name server containing the requested IP address, the recursive resolver sends the response to the client.
During this process, the recursive resolver caches the information received from the authoritative name server. When a client requests an IP address for a domain that another client has recently requested, the resolver can bypass the communication process with the domain server and provide the requested record from the cache to the client.
DNS Root Name Server
The Top Level Domain (TLD) server maintains information for all domains sharing a common domain extension, such as .com, .net, etc. For example, the .com TLD name server contains information for every website ending in ".com". If a user is searching for upyun.com, after receiving a response from the root name server, the recursive resolver will send a query to the .com TLD name server, which will then respond via the authoritative name server for that domain.
Authoritative Name Server
When the recursive resolver receives a response from the TLD name server, that response directs the resolver to the authoritative name server. The authoritative name server is typically the final step in the resolver's IP address lookup process. The authoritative name server contains information for a specific domain (e.g., upyun.com) and can provide the server IP address found in the DNS A record to the recursive resolver. Or, if the domain has a CNAME (alias) record, it will provide an alias domain to the recursive resolver, which must then perform a new DNS lookup to obtain the record (typically an A record containing the IP address) from the authoritative name server.
DNS Records
In the authoritative name server, DNS records are indispensable.
DNS records (also known as zone files) are instructions located in the authoritative DNS server that provide information about a domain, including which IP addresses are associated with the domain and how requests to that domain should be handled. Additionally, all DNS records have a "TTL" (Time To Live), which indicates how often the DNS server refreshes that record.

Common DNS records include the following:
- A Record: A record that saves the IP address of a domain.
- CNAME Record: An alias that forwards a domain or subdomain to another domain, without providing an IP address.
- MX Record: Directs mail to an email server.
- TXT Record: Allows administrators to store text comments in the record.
- NS Record: Stores the name server for DNS entries.
- SOA Record: Stores administrative information for the domain.
- SRV Record: Specifies the port used for a specific service.
- PTR Record: Provides the domain name in reverse lookups.
- Among these, A records and CNAME records are the most commonly used for domain resolution.
DNS A Record
"A" stands for "Address." This is the most basic type of DNS record, indicating the IP address of a domain. For example, extracting the DNS records for upyun.com, its "A" record currently returns the IP address 115.231.97.2. "A" records only save IPv4 addresses; if a site has an IPv6 address, it will use an "AAAA" record.
DNS CNAME Record
When a domain or subdomain is an alias for another domain, a "Canonical Name" (CNAME) record is used instead of an A record. Suppose www.example.com has a CNAME record with the value "example.com". This means that when a DNS server accesses the DNS records for www.example.com, it actually triggers another DNS lookup for example.com, returning the IP address of example.com. All CNAME records must point to a domain, not an IP address.

For CDNs, since there are nodes distributed all over the world, A records are completely insufficient. Furthermore, nodes need to change constantly based on the user's local DNS region and carrier. Therefore, using CNAME records for domain resolution is a very convenient management method. After setting up an alias record, there is no need to worry about how the node IPs change.
How DNS Works
Now that we understand the types of DNS, let's look at how DNS works.
Since every internet-connected device is assigned an IP address, when a user enters a domain name in a web browser, the client computer initiates a request. DNS then works behind the scenes through a process called "DNS resolution" to query the corresponding server IP and establish a connection. It is important to note that if you have visited this domain before, your local machine will have a cache, and the DNS lookup process will skip some steps, making the lookup faster.
A complete DNS lookup involves the following steps:
- Taking "www.xiaoz.me" as an example, the user enters "www.xiaoz.me" in the browser, and the query is transmitted to the Internet and received by the DNS recursive resolver.
- The resolver queries the DNS root name server (.).
- The root server responds to the resolver with the address of the TLD name server (.me) that stores its domain information. When searching for .me, our request is directed to the .me TLD.
- The resolver sends a request to the .me TLD.
- The TLD server then responds with the IP address of the domain name server www.xiaoz.me for that domain.
- The recursive resolver sends the query result to the domain's name server.
- The IP address of www.xiaoz.me is then returned to the resolver from the name server.
- The DNS resolver responds to the web browser with the IP address of the originally requested domain.

After these steps of DNS lookup return the IP address for upyun.com, the browser can then make a request to that webpage:
- The browser sends an HTTP request to that IP address.
- The server located at that IP returns the webpage to the browser (Step 10).
After reading this introduction to DNS, do you now have a better understanding of it? Once you understand DNS, if you encounter situations where you cannot access web pages, you can resolve them by modifying the DNS. Isn't it simple and convenient?