What happens when the browser enters a URL? The first step, of course, is DNS resolution, the following to analyze the DNS resolution process.

what

First of all, what’s DNS?

DNS is a Domain Name System that manages the mapping between Domain names and IP addresses. In plain English, it’s a list of key-value pairs.

The domain name

So let’s take a look at the structure of the domain name. For example, first there is a domain name: tlab.cloud.tencent.com. The last com we see is the top-level domain name. Level domain, so Tencent is level 2 domain, Clloud is level 3 domain, and so on.

The DNS

So how does DNS resolve a domain name when it’s typed into a browser? Divided into the following steps:

  1. Local hosts file
  2. Local DNS cache
  3. DNS Server Cache
  4. The DNS server performs recursive lookup

Local hosts file

Modifying the hosts file is not new to developers, so that we can access the desired machine through the domain name without changing the configuration of the online domain name.

Local DNS cache

If the hosts file is not present, DNS checks the local DNS cache and returns the corresponding IP address if it is present. Here is my DNS resolution for tlab.cloud.tencent.com. Since it has been resolved before, there is the corresponding IP address in the cache: 193.112.230.97.

DNS Server Cache

If you are accessing a domain name for the first time, there is no local cache.

After connecting to the network, our computer will have the address of the corresponding DNS server, as shown below:

Tlab.cloud.tencent.com is the IP address of tlab.cloud.tencent.com. The IP address of tlab.cloud.tencent.com is the IP address of tlab.cloud.tencent.com.

The DNS server first looks at its cache and returns it if it has one.

The DNS server performs recursive lookup

If the DNS server also has no cache, then recursive lookups are required.

First, we dig math tlab.cloud.tencent.com to see the answer

Here we’ll see the domain name added at the end. In fact, all domain names are actually behind. Root, which is the root domain name, because everyone is the same, so I omit it.

Tlab.cloud.tencent.com. 600 IN A 193.112.230.97Copy the code

Moving on, let’s look at how DNS servers recursively lookup.

  1. Query the root domain Name and obtain the Name Server (NS) and Address (A) of the top-level domain Name.com. NS is the Name of the top-level domain Name and A is the IP Address of NS
  2. Ask for the top-level domain name and get the NS and A for the secondary domain.tencnet.com
  3. Ask for A secondary domain name to get NS and A for the tertiary domain name.cloud.tencent.com
  4. Ask for A level 3 domain name to get NS and A for the level 4 domain name.tlab.cloud.tencent.com
  5. Finally, the IP address of tlab.cloud.tencent.com is returned to the user and cached
  6. The user obtains the real IP address and caches it

Write in the last

DNS caching is something we use every day, but of course we don’t use it every day, and it helps us get more familiar with the development process.