Chrome browser obtains URL mapping IP address DNS resolution process in detail

Detailed process description of the analysis stage

step illustrate
Browser input: http://www.baidu.com
Find the browser's own DNS cache: chrome://net-internals/#dns
Windows system: find the system hosts file, Linux system: find the /etc/hosts file
The browser will initiate a DNS system call (initiate a domain name resolution request to the local domain name server)
The local domain name server LDNS initiates for our browser迭代 DNS 解析请求
The local domain name server returns the query IP result to the client (browser)

Find the browser's own DNS cache introduction

Enter the following address in the url address bar of the chrome browser

chrome://net-internals/#dns

visit page results

insert image description here

Resolved lP addresses of “www.baidu.com”:[“112.80.248.75”, “112.80.248.76”].
No data on which protocols are supported.

Host resolver cache

Host resolver cache (click Clear host cache to clear the cache record)

Directly request access to its corresponding IP

Open 112.80.248.75 in the browser: default port 80 (access results are as follows)

insert image description here

Windows system looks for hosts file

open path

C:\Windows\System32\drivers\etc

etc directory display

insert image description here

There will be a hosts file inside, right-click to open with a notebook. Add the following format at the bottom:IP + 空格 + 网址

For example, 127.0.0.1 www.baidu.com, then when you visit Baidu, you actually visit 127.0.0.1 (your own computer)

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

127.0.0.1 www.baidu.com

We use Golang to start a 127.0.0.1 server process, verify

package main

import ("net/http")

func handle(w http.ResponseWriter, req *http.Request) {
    
    
	w.Write([]byte("hello world"))
}

func main() {
    
    
	http.HandleFunc("/", handle)
	http.ListenAndServe("127.0.0.1:80", nil)
}

Because the default port is 80, you can omit the port number and directly access the 127.0.0.1 IP. The access results are displayed:

insert image description here
Because we configured it in the hosts file of the window 127.0.0.1 www.baidu.com, now we verify the above

Visit www.baidu.com domain name address (the result is the result of Baidu search page)

insert image description here

problem causes

Why didn't it appear instead of hello world, and the result was a Baidu search page?

Reason: The browser searches its own DNS cache first, and only searches the hosts file under Window if no result is found, so we delete the browser DNS cache first.

Click in chrome://net-internals/#dns clear host cache( # 查找浏览器自身 DNS 缓存介绍mentioned )

Verify 127.0.0.1 www.baidu.com

Modify the hosts file in Window in # Window 系统查找 hosts 文件the previous section, and delete the host cache of the chrome browser, and then continue to try.

Visit the domain name address of www.baidu.com (this time it is more direct, and you will not be able to access this website directly)

insert image description here

Analysis reason: We double-click the url address of the chrome browser, and the display results are as follows:

insert image description here
Is this because of chrome browser's domain name security policy?

Some website http protocol and https protocol are two services, sometimes need to access the http address, but chrome will convert to https request address by default, and it will keep jumping, so we can't access the http website, which is very annoying.

How to solve?

Enter the following address in the chrome browser address:

chrome://net-internals/#hsts

Fill in www.baidu.com address in the Delete domain security policies at the bottom, and click Delete

insert image description here

Continue to visit the domain name address of www.baidu.com (the visit is successful, the result is hello world)

insert image description here

Continue testing: Next, delete 127.0.0.1 www.baidu.com in the hosts file, and then continue to visit www.baidu.com domain name address, you can find it, the result is hello world

Reason: The Chrome browser searches its own DNS cache first, and after finding the result, it will not go to the hosts file under Window to find the mapping relationship between the domain name and the IP.

So if we delete the DNS cache of chrome, and then visit www.baidu.com, first search our own DNS cache and find no results, then go to the hosts file of Window and find no results, then search... (The following sections will mention to) until the Baidu search page is mapped.

insert image description here

Local domain name server resolution (LDNS)

If the corresponding entry is not found in the hosts file, the browser will initiate a DNS system call, and it will send the preferred DNS server configured locally (LDNS is generally provided by telecom operators, and DNS servers such as Google can also be used) ) to initiate a domain name resolution request (through the UDP protocol to initiate a request to DNS port 53, this request is a recursive request, that is, the operator's DNS server must provide us with the IP address of the domain name).

The DNS server in the local computer network settings is usually set automatically, and the automatically set DNS address is usually the IP address of the management wifi router; of course, it can also be set manually, such as the common Google DNS server 8.8.8.8

local name server

In our network configuration, there will be an item of "DNS server address". This address is used to solve the above-mentioned what to do if the two processes cannot be resolved. The operating system will send this domain name to the LDNS set here , which is the domain name server for the region.

This DNS usually provides a DNS resolution service for your local Internet access. For example, if you access the Internet at school, then your DNS server must be at your school. For example, if you are connected to the Internet in a residential area, then this DNS is the application provider that provides you with access to the Internet, that is, China Telecom or China Unicom, which is commonly referred to as SPA, then this DNS is usually also in your city’s Somewhere, usually not far away.

The performance of this dedicated domain name resolution server will be very good. They will generally cache the domain name resolution results. Of course, the cache time is controlled by the expiration time of the domain name. Generally, the cache space is not the main factor affecting the domain name expiration. About 80% of the domain name resolution has been completed here, so LDNS mainly undertakes the domain name resolution work.

The operator's DNS server first searches its own cache, finds the corresponding entry, and if it has not expired, the resolution is successful.

How to check local DNS server?

For the address of the local DNS server, the Windows system can use the command ipconfigto view it. Under the Linux and Mac systems, directly use the command cat /etc/resolv.confto view the LDNS service address.

insert image description here

View configuration information: Please click the properties of the WiFi connected to the computer to view the network property information (for example, as shown below)

SSID:	TP-LINK_hh
协议:	Wi-Fi 4 (802.11n)
安全类型:	WPA2-个人
网络频带:	2.4 GHz
网络通道:	6
链接速度(接收/传输):	300/300 (Mbps)
IPv4 地址:	192.168.1.106
IPv4 DNS 服务器:	172.16.4.4 210.29.152.xxx(前一个是本地局域网,后一个是公网 IP)

Root domain name server resolution (Root Server)

4 different types of nameservers

根域名服务器

The root domain name server is the highest-level domain name server. Each root domain name server knows the domain names and IP addresses of all top-level domain name servers. There are 13 root domain name servers with different IP addresses on the Internet. When the local domain name server sends a query request to the root domain name server, the router forwards the query request message to the root domain name server closest to the DNS client. This speeds up the DNS query process and makes more rational use of Internet resources.

顶级域名服务器

These nameservers are responsible for managing all second-level domain names registered with that top-level nameserver. When it receives a DNS query request, it will give a corresponding answer (it may be the final result, or it may be the IP address of the next-level authoritative domain name server).

权限域名服务器

These name servers are responsible for managing domain names for a zone. The domain name of each host must be registered with an authoritative domain name server. Therefore, the authoritative domain name server knows the mapping relationship between the domain name and the IP address under its jurisdiction. In addition, the authoritative domain name server also knows the address of its subordinate domain name server.

本地域名服务器

Local name servers do not belong to the hierarchy of name servers described above. When a host sends a DNS request message, the message is first sent to the host's local domain name server. The local domain name server acts as a proxy and forwards the message to the hierarchical structure of the above domain name server. The local domain name server is relatively close to the user, generally not more than a few routers away, and may also be in the same local area network. The IP address of the local domain name server needs to be directly configured in the host that needs domain name resolution.

Analysis process diagram

insert image description here

Query root domain name server (Root DNS)

If LDNS does not find the corresponding entry, it will be initiated by the local domain name server for our browser 迭代 DNS 解析请求. It will first find the DNS IP address of the root domain (this DNS server has 13 built-in DNS IP addresses of the root domain), find the DNS address of the root domain, and initiate a request to it.

For example: What is the IP address of the domain name www.baidu.com?

The root domain name server returns a primary domain name server (gTLD Server) address of the queried domain to the local domain name server. gTLD is an international top-level domain name server, such as .com, .cn, .org, etc. There are only about 13 in the world.

The root domain finds that this is a domain name of a top-level com domain, so it tells the local domain name server that I don't know the IP address of this domain name, but I know the IP address of the com domain, and asks the local domain name server to find it.

Query top-level domain name server (Top Level DNS)

The local domain name server (Local DNS Server) then sends a request to the gTLD server returned in the previous step. So the local domain name server gets the IP address of the com domain, and then initiates a request to the IP address of the com domain (what is the IP address of the domain name www.baidu.com?)

The server in the com domain tells the local domain name server that I don’t know the IP address of the domain name www.google.com, but I know the DNS address of the domain name baidu.com, and let the local domain name server find it.

Query authoritative domain name server (Authoritative DNS)

The gTLD server that accepts the request looks up and returns the address of the Name Server domain name server corresponding to this domain name. This Name Server is usually the registered domain name server.

For example, if you apply for a domain name from a certain domain name service provider, then the domain name resolution task will be completed by the server of this domain name provider.

The local domain name server (Local DNS Server) initiates a request to the DNS address of the domain name google.com (this is generally provided by the domain name registrar, such as Wanwang, Xinwang, etc.) (please ask the IP address of the domain name www.baidu.com what is it?)

At this time, I checked the DNS server of the baidu.com domain, and it was indeed here, so I sent the found result to the local domain name server. At this time, the local domain name server got the IP address corresponding to the domain name wwwbaidu.com. Finally, the local domain name server returns the result to the host of the user's browser.

DNS iterative and recursive queries

DNS domain name resolution process: Domain name resolution includes two query methods, namely recursive query and iterative query.

recursive query

Recursive query is a query mode of DNS server. In this mode, DNS server receives a client request and must reply to the client with an accurate query result. If the DNS server does not store query DNS information locally, the server queries other servers and returns the query results to the client.

insert image description here
iterative query

Another query method of the DNS server is iterative query. The DNS server will provide the client with the address of other DNS servers that can resolve the query request. When the client sends a query request, the DNS server does not directly reply to the query result, but tells the client Another DNS server address, the client computer then submits a request to this DNS server, and cycles in turn until the result of the query is returned.

insert image description here
Since the recursive query is too burdensome for the queried domain name server, the following mode is usually adopted: the query from the requesting host to the local domain name server is a recursive query, while the query from the DNS server to the DNS server is an iterative query.

Comprehensive illustration of DNS iterative and recursive queries

insert image description here

Guess you like

Origin blog.csdn.net/qq_47452807/article/details/129547712