Publish: 2021-05-20 | Modify: 2021-05-20
I saw a popular science article about DNS on the Upyun public account and thought it was good, so I reposted it and drew a simple flowchart based on my understanding of the article.
The flowchart was created using Processon. Here is the original article with some modifications.
Have you ever encountered a situation where you can send messages on QQ but cannot open webpages, even though your network connection appears to be normal? Many people feel confused in such situations. So how do we deal with this and what exactly is going on?
After searching online, I found that in general, computers automatically obtain DNS servers and manual configuration is not required. However, in some special cases, if the DNS server is not obtained or if the server is experiencing issues, we need to manually change the DNS to ensure normal webpage access. The inability to display webpages is often caused by DNS configuration errors, which can be resolved by modifying the DNS settings.
So where exactly is the DNS and how can we change it?
DNS (Domain Name System) is an abbreviation for the Domain Name System. It is one of the foundations of the Internet and is used to map domain names to IP addresses, similar to how a phone book maps names to phone numbers. When we enter a web address in a browser, DNS queries are used to convert it into the corresponding IP address of the associated server. Without DNS, we would need to remember the IP addresses of each website in order to access them.
In the early days of the Internet, this was relatively easy to do. People could easily associate specific IP addresses with specific computers and access websites by directly entering the IP address in the browser. However, as more and more devices and people joined this rapidly expanding network, the number of IP addresses grew and remembering them became a burden. Internet users wanted a more memorable address composed of words, which led to the birth of domain names.
In the 1970s and early 1980s, these names and addresses were assigned by one 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.
It is obvious that as the Internet developed, this approach became unsustainable as the number of addresses grew. In 1983, Paul Mockapetris, a researcher from the University of Southern California, developed the initial domain name system and named it DNS. Although DNS has undergone significant changes since then, fundamentally, it still works the same way as it did 40 years ago.
Before delving into the role and workings of DNS in the network, let's take a look at the categories of DNS servers.
All DNS servers belong to one of the following four categories: recursive resolver, root domain server, TLD domain server, and authoritative domain server. In a typical DNS lookup, these four types of servers work together to provide the IP address of the specified domain to the client.
The recursive resolver (also known as the DNS resolver) is the first stop in a DNS query. It acts as an intermediary between the client and the DNS domain server. When the recursive resolver receives a DNS query request from a web client, it responds using cached data or sends a request to the root domain server, then to the TLD domain server, and finally to the authoritative domain server. Once it receives a response from the authoritative domain 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 domain server. When a client requests the IP address of a domain that another client has recently requested, the resolver can bypass the process of communicating with the domain server and provide the requested record from the cache.
The top-level domain (TLD) server maintains the information of all domain names with shared generic domain extensions, such as .com, .net, etc. For example, the .com TLD server contains information about every website ending with ".com". If a user is searching for upyun.com, after receiving a response from the root domain server, the recursive resolver will send a query to the .com TLD domain server, which will respond by querying the authoritative domain server for that domain.
When the recursive resolver receives a response from the TLD domain server, it is directed to the authoritative domain server. The authoritative domain server is usually the last step in the process of resolving the IP address. It contains the information of a specific domain (e.g., upyun.com) and can provide the server IP address found in the DNS A record for the recursive resolver. If the domain has a CNAME (alias) record, it will provide an alias domain to the recursive resolver, which will then have to perform a new DNS lookup to obtain the record (usually an A record containing the IP address) from the authoritative domain server.
DNS records are essential in authoritative domain servers.
DNS records (also known as zone files) are instructions located in authoritative DNS servers that provide information about a domain, including which IP addresses are associated with it and how to handle requests for that domain. Additionally, all DNS records have a "TTL" (Time to Live), which represents the duration for which the DNS server caches the record before refreshing it.
Common types of DNS records include:
"A" stands for "address," and it is the most basic type of DNS record that indicates the IP address of a domain. For example, when extracting the DNS record of upyun.com, its A record currently returns the IP address 115.231.97.2. A records only store IPv4 addresses, and if a site has an IPv6 address, it will use an "AAAA" record.
When a domain or subdomain is an alias for another domain, a "canonical name" (CNAME) record is used instead of an A record. For example, if www.example.com has a CNAME record with the value "example.com," it means that when a DNS server accesses the DNS record of www.example.com, it actually triggers another DNS lookup for example.com and returns the IP address of example.com. All CNAME records must point to a domain, not an IP address.
For CDNs, A records are not sufficient due to the presence of nodes distributed around the world. The IP addresses of these nodes need to change based on the user's local DNS location and ISP. Therefore, using CNAME records for domain resolution is a convenient management method. Once the alias record is set up, there is no need to worry about the changing IP addresses of the nodes.
Now that we know there are different types of DNS servers, let's take a look at how DNS works.
Since each device connected to the Internet is assigned an IP address, when a user enters a domain name in a web browser, the request is initiated by the client computer, and then DNS performs a process called "DNS resolution" in the background to query the corresponding server IP address and establish a connection. It is important to note that if you have previously accessed a domain name, your local cache will store the information, allowing DNS to skip some steps and make the lookup faster.
A complete DNS lookup involves the following steps:
Once the IP address of upyun.com is obtained through the DNS lookup, the browser can send a request to that webpage:
After reading about DNS, do you now have a better understanding of it? With this knowledge, you can solve issues of unable to access webpages by modifying DNS settings. Isn't it simple and convenient?
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.