Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The complete process for users to visit a website

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

After the browser enters the domain name you want to access, the browser will resolve the domain name to get the IP address. After the connection through TCP, there will be two kinds of messages for data transmission, as well as request message and response message. Finally, communication can be realized. Therefore, if you want to achieve communication, you must first understand the parsing principle of DNS and the process of TCP connection channel.

Theoretical content:

1. The introduction and principle of DNS

2. Introduction of TCP/IP protocol and three-way handshake and four-time wave.

3. Introduction of HTTP protocol and request and response message.

4. The complete process of the user accessing the browser

1. The introduction and analytical principle of DNS.

1) tell me what DNS is:

DNS (Domain Name System, Domain name system), a distributed database on the Internet as a mapping between domain names and IP addresses, can make it more convenient for users to access the Internet without having to remember the IP strings that can be read directly by the machine. The process of getting the IP address corresponding to the host name through the host name is called domain name resolution (or host name resolution). DNS protocol runs on top of UDP protocol, using port number 53. The essence of visiting a website is to parse its domain name and get its IP address, and then go to its website.

2) the analytical principle of DNS:

Principle steps:

1) the system will first look up the local DNS cache and hosts file information to confirm whether there is an IP address corresponding to the domain name www.baidu.com. If so, directly access the www.baidu.com domain name server corresponding to this IP address.

2) if it is not found, the system will send the browser's resolution request to the DNS server specified by the local host, called LDNS. If the LDNS server has the IP address corresponding to the domain name www.baidu.com, it will be returned to the client's browser, and if not, continue to request other DNS servers.

3) the LDNS server will request the resolution of the domain name www.baidu.com from the root (.) of the DNS system. There are only 13 root DNS servers in the world, and the root domain name server has no record of domain name www.baidu.com resolution. However, it will have a resolution record of the top-level domain .com corresponding to the domain name www.baidu.com, so it directly returns the DNS address corresponding to the top-level domain .com to the LDNS server.

4) after the LDNS server obtains the DNS server address corresponding to the top-level domain .com, it will go to the .com server to request the resolution of the www.baidu.com domain name. There will be no resolution record of www.baidu.com on the top-level domain name server. But it has a resolution record of the parent domain name of www.baidu.com, namely baidu.com. Therefore, the top-level domain name .com server will return the IP address of the DNS server corresponding to baidu.com to LDNS.

5) after the LDNS server receives the IP address corresponding to baidu.com, it will go to the baidu.com domain name server to request the domain name resolution of www.baidu.com. The DNS server corresponding to the Baidu.com domain name is the authorized DNS server for the domain name. This DNS server is the server used by enterprises to manage resolution when purchasing domain names.

6) the baidu.com domain name DNS server will resolve the IP address corresponding to the www.baidu.com domain name, and then send it to LDNS.

7) LDNS sends the parsed result, the IP address corresponding to www.baudu.com, to the browser of the client. And LDNS caches its domain name and corresponding address into cache.

8) after receiving it, the client browser will also cache its domain name and corresponding IP address in the DNS cache and hosts file.

2. Introduction of TCP/IP protocol and three-way handshake and four-time wave.

1) tell me what the TCP/IP protocol is

The abbreviation of Transmission Control Protocol/Internet Protocol, which is translated into Chinese as Transmission Control Protocol / Internet Protocol, also known as Network Communication Protocol, is the most basic protocol of Internet and the foundation of Internet Internet. It consists of IP protocol of network layer and TCP protocol of transport layer. TCP/IP defines standards for how electronic devices connect to the Internet and how data is transferred between them. The protocol adopts a four-layer hierarchical structure, and each layer calls the protocol provided by its next layer to complete its own requirements. In popular terms: TCP is responsible for finding problems with the transmission, sending signals whenever there is a problem, asking for retransmission until all data is safely and correctly transmitted to the destination. IP assigns an address to every connected device on the Internet.

2) the meaning of each state is as follows:

(1) LISTEN-listens for connection requests from remote TCP ports

(2) SYN-SENT-wait for a matching connection request after sending a connection request

(3) SYN-RECEIVED-wait for confirmation of a connection request after receiving and sending a connection request

(4) ESTABLISHED- represents an open connection, and data can be transmitted to the user.

(5) FIN-WAIT-1-waits for a connection break request from a remote TCP, or a confirmation of a previous connection break request

(6) FIN-WAIT-2-wait for a connection disconnection request from a remote TCP

(7) CLOSE-WAIT-waiting for a connection disconnection request from a local user

(8) CLOSING-wait for the remote TCP to confirm the connection break

(9) LAST-ACK-waits for confirmation of the connection break request originally sent to the remote TCP

(10) TIME-WAIT-wait enough time to ensure that the remote TCP receives an acknowledgement of the connection disconnection request

(11) CLOSED-without any connection statu

3) TCP three-way handshake

The so-called three-way handshake (Three-way Handshake) means that when establishing a TCP connection, the client and server need to send a total of 3 packets.

The purpose of the three-way handshake is to connect to the designated port of the server, establish a TCP connection, synchronize the serial numbers and confirmation numbers of both sides of the connection, and exchange TCP window size information. In socket programming, when the client executes connect (). Will trigger a three-way handshake.

Three-way handshake:

1) first handshake: when establishing a connection, client A sends a SYN packet (SYN=j) to server B, enters the SYN_SEND state, and waits for server B to confirm.

2) the second handshake: when server B receives the SYN packet, it must confirm customer A's SYN (ACK=j+1), and also send a SYN packet (SYN=k), that is, SYN+ACK packet. Server B enters the SYN_RECV status at this time.

3) the third handshake: client A receives the SYN+ACK packet of server B and sends the confirmation packet ACK (ACK=k+1) to server B. after the packet is sent, client An and server B enter the ESTABLISHED state and complete the three-way handshake.

4) TCP waved his hand four times

The removal of a TCP connection requires sending four packets, so it is called a four-wave (four-way handshake). Either the client or the server can initiate the waving action actively. In socket programming, either party executes the close () operation to produce the waving operation.

Four waves:

1) first wave: client A sends a FIN to turn off data transfer from client A to server B.

2) second wave: server B receives this FIN, and it sends back an ACK, confirming that the serial number is the received serial number plus 1. Like SYN, a FIN will take a sequence number.

3) the third wave: server B closes the connection to client An and sends a FIN to client A.

4) the fourth wave: client A sends back the ACK message confirmation and sets the confirmation serial number to receive the serial number plus 1.

3. Introduction of HTTP protocol and request and response message.

1) HTTP message

There are many insiders in the HTTP message, and the fields of these lines are made up of some ASCII code strings, but the length of each field is different. HTTP messages can be divided into two types, one is the HTTP message sent from the web client to the web server, called request security, and the other is the message sent from the web server to the client, called the response message. The format of the two messages is basically the same.

(1) introduction of request message

(2) the content and format of the request message are as follows:

1) request line

Function: used to explain what the client wants to do.

Content: including method fields GET and URL fields and HTTP protocol version

2) request header

Function: send the requested information to the server through the client

Content: including media type, language type, support compression, client type, host and other information.

3) blank line

Function: tell the server that the following content does not belong to the request header information.

4) request message body

Function: used to describe what the client wants to do.

Content: view information and apply post method.

(3) introduction of response message

(4) the content and format of the request message are as follows:

1) status line

Function: used to describe the status of the server responding to the client.

Content: including laundry and version number, digital status code, status status

2) response head

Function: send the relevant information of the response to the client through the server

Content: including Location, server, connect, vary, etc.

3) blank line

Function: tell the client that the following content does not belong to the response header information.

4) response message body

Purpose: used to load data to be returned to the client

Content: including text, html, video or pictures.

(5) the understanding of GET and POST.

GET: use the GET method when the client wants to read a resource from the server. The GET method requires the server to place the resource located by URL in the data part of the response message and send it back to the client, that is, to request a resource from the server. When using the GET method, the request parameter and the corresponding value are appended to URL, using a question mark ("?") Represents the end of the URL and the beginning of the request parameter, and the length of the passed parameter is limited. For example, / index.jsp?id=100&op=bind,

POST: when the client provides more information to the server, you can use the POST method, and the POST method can submit the data to the server, such as completing the submission of the form data and submitting the data to the server for processing. GET is generally used to obtain / query resource information. POST is accompanied by user data, which is generally used to update resource information. The POST method encapsulates the request parameters in the HTTP request data and appears in the form of name / value, which can transfer a large amount of data.

4. The complete process of the user accessing the browser

1. The client enters the address of the domain name to be accessed in the browser, such as www.baidu.com

2. The browser requests to resolve the DNS server and convert the domain name www.baidu.com into the IP address of the web server.

1) the system will first look up the local DNS cache and hosts file information to confirm whether there is an IP address corresponding to the domain name www.baidu.com. If so, directly access the www.baidu.com domain name server corresponding to this IP address.

2) if it is not found, the system will send the browser's resolution request to the DNS server specified by the local host, called LDNS. If the LDNS server has the IP address corresponding to the domain name www.baidu.com, it will be returned to the client's browser, and if not, continue to request other DNS servers.

3) the LDNS server will request the resolution of the domain name www.baidu.com from the root (.) of the DNS system. There are only 13 root DNS servers in the world, and the root domain name server has no record of domain name www.baidu.com resolution. However, it will have a resolution record of the top-level domain .com corresponding to the domain name www.baidu.com, so it directly returns the DNS address corresponding to the top-level domain .com to the LDNS server.

4) after the LDNS server obtains the DNS server address corresponding to the top-level domain .com, it will go to the .com server to request the resolution of the www.baidu.com domain name. There will be no resolution record of www.baidu.com on the top-level domain name server. But it has the parent domain name of www.baidu.com, baidu.com. Therefore, the top-level domain name .com server will return the IP address of the DNS server corresponding to baidu.com to LDNS.

5) after the LDNS server receives the IP address corresponding to baidu.com, it will go to the baidu.com domain name server to request the domain name resolution of www.baidu.com. The DNS server corresponding to the Baidu.com domain name is the authorized DNS server for the domain name. This DNS server is the server used by enterprises to manage resolution when purchasing domain names.

6) the baidu.com domain name DNS server will resolve the IP address corresponding to the www.baidu.com domain name, and then send it to LDNS.

7) LDNS sends the parsed result, the IP address corresponding to www.baudu.com, to the browser of the client. And LDNS caches its domain name and corresponding address into cache.

8) after receiving it, the client browser will also cache its domain name and corresponding IP address in the DNS cache and hosts file.

3. The browser parses the default break number from the accessed IP address (URL): 80

4. The browser uses the parsed IP address and port number to web the server to establish a TCP connection channel.

1) first handshake:

When establishing a connection, client A sends a SYN packet (SYN=j) to Server B, enters the SYN_SEND state, and waits for Server B to confirm.

2) second handshake:

When server B receives the SYN packet, it must confirm the SYN (ACK=j+1) of customer A, and also send a SYN packet (SYN=k), that is, SYN+ACK packet. Server B enters the SYN_RECV state at this time.

3) the third handshake:

Client A receives the SYN+ACK packet of server B and sends an acknowledgement packet ACK (ACK=k+1) to server B. after the packet is sent, client An and server B enter the ESTABLISHED state and complete the three-way handshake.

5. After establishing a TCP connection, the browser sends a HTTP request message to the web server.

1) request line

Function: used to explain what the client wants to do.

Content: including method fields GET and URL fields and HTTP protocol version

2) request header

Function: send the requested information to the server through the client

Content: including media type, language type, support compression, client type, host and other information.

3) blank line

Function: tell the server that the following content does not belong to the request header information.

4) request message body

Function: used to describe what the client wants to do.

Content: view information and apply post method.

6. The web server responds and reads the request information of the browser, and then returns a HTTP response message.

1) status line

Function: used to describe the status of the server responding to the client.

Content: including laundry and version number, digital status code, status status

2) response head

Function: send the relevant information of the response to the client through the server

Content: including Location, server, connect, vary, etc.

3) blank line

Function: tell the client that the following content does not belong to the response header information.

4) response message body

Purpose: used to load data to be returned to the client

Content: including text, html, video or pictures.

7. The web server closes the HTTP connection, closes the TCP connection, and the web server displays the visited website content to the screen.

1) waving for the first time:

Client A sends a FIN to turn off data transfer from client A to server B.

2) the second wave:

Server B receives this FIN and sends back an ACK confirming that the sequence number is the received sequence number plus 1. Like SYN, a FIN will take a sequence number.

3) the third wave:

Server B closes the connection to client An and sends a FIN to client A.

4) waving for the fourth time:

Client A sends back an ACK message for confirmation and sets the confirmation sequence number to receive the sequence number plus 1.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report