Uncover the mysterious navigation behind the Internet, DNS domain name resolution
In the vast information system of the Internet, the DNS (Domain Name System) plays a crucial role in navigation, acting as a precise map that guides users to the target website without error.
The purpose of this article is to delve into the core concepts of DNS, how it works, and how important it is to keep the Internet running efficiently.
The following diagram clearly illustrates the entire process of DNS domain name resolution.
What is DNS
The DNS (Domain Name System) is a core component of the Internet and is responsible for translating easy-to-remember domain names (e.g., www.baidu.com) into IP addresses that computers can understand (e.g., 39.156.66.10). This system enables users to easily access websites and other network resources through a distributed database and a multi-level query mechanism, ensuring the normal operation and efficient navigation of the Internet. DNS runs on the UDP protocol and uses port 53.
Domain name structure resolution
As shown in the diagram above, the Domain Name System has a hierarchical tree structure. At the top is the root server, and below are the top-level domains (e.g., .com, . .net and .cn, etc.). Most users register second-level domain names (such as baidu.com), which are managed by businesses and their teams. There are deeper subdomains, but they won't be discussed in detail here. On the whole, the domain name system is designed to be detailed layer by layer from the global to the local.
DNS resolution process
As shown in the diagram above, we will elaborate on the DNS resolution process:
- When you type a web address (e.g., http://www.kwpmp.cn) into a browser on your computer or phone, the browser will first try to find the actual IP address of the website through DNS resolution. If the local cache does not have that information, it queries the root DNS server. The root server tells you the location of the server responsible for the .cn domain name. In this way, the exact location of the kwpmp.cn can be found step by step.
- When the recursive server obtains the authoritative server address of the .cn, it asks the authoritative server if it knows the location of the www.kwpmp.cn. Subsequently, the authoritative server of .cn looks up and returns the address of the kwpmp.cn server.
- Continue to check the kwpmp.cn's authoritative server for this address, and the kwpmp.cn server gives the answer: 10.10.10.168.
- Finally, you can make a link to http and visit the website smoothly.
Once the recursive server finds the resolution record of the domain name, it saves it locally. In this way, the next time a client comes to query the same domain name, there is no need to look it up step by step. Because the local server already has a cache, it can directly return the www.kwpmp.cn A record to the client.
DNS resource records
Domain | TTL | Class | Type | rdata |
www.kwpmp.cn | 600 | IN | A | 10.10.10.168 |
When we associate a domain name with information about it, it's called a Resource Record (RR). For example, when you look up kwpmp.cn this URL, the results you get will have this information:
- TTL: is the lifetime period, which is the length of time that the recursive server will store the resource record in the cache.
- Network protocol type: its representative identity is IN, IN is the internet, and the protocol mainly supported by the DNS system is IN.
- type: is the type of resource record, and most websites are A records (IPv4 host addresses).
- rdata: resource record data, which is the information data associated with the domain name.
The query method of DNS
There are two main modes of DNS queries: recursion and iteration.
Recursive queries
When a client initiates a DNS resolution request, if the local DNS server cannot directly resolve the domain name, it will perform a recursive query to other DNS servers on behalf of the client until it finds an answer and returns it to the client. During this process, the client waits for a response.
Iterative queries
When a client (a subordinate server) initiates a DNS resolution request, if the parent DNS server is unable to provide the resolution result directly, it returns the IP address of another DNS server that may know the answer. The client then continues to query the new DNS server and repeats the process until the final resolution result is obtained.
Typically, queries between the PC and the local DNS server use recursive queries. Recursive queries are also often used when DNS servers need to query each other. This is like the one shown in the image below.
How to configure DNS in Linux
To configure DNS in Linux, you can edit the /etc/resolv.conf file, and the following steps are as follows:
(1) Edit /etc/resolv.conf
Open the terminal and edit the /etc/resolv.conf file using a text editor such as nano or vim:
sudo nano /etc/resolv.conf
- 1.
(2) Add a DNS server
Add the address of the DNS server to the file. Commonly used public DNS servers are:
nameserver 8.8.8.8
nameserver 114.114.114.114
- 1.
- 2.
(3) Save and Exit
Save the file and exit the editor. If you are using nano, you can press Ctrl + O to save and Ctrl + X to exit.
(4) Test the DNS configuration
Run the nslookup or dig command to check whether the DNS resolution is normal:
nslookup www.baidu.com.com
- 1.
conclusion
DNS is an integral part of the Internet, connecting users to network resources in an efficient and reliable manner. Understanding how DNS works can help us better manage and maintain our network services.