Introduction to network technology (2): The communication process (macro process) of two hosts (client and server)

自己写文章习惯性在每一个小节上做总结,有时候方便理解可以先看总结的内容。
This chapter looks at the communication process between two hosts from a macro (hardware) perspective.

This series of articles
network technology entry (a): a basic understanding of network technology
network technology entry (2): The two hosts (client and server) communication process (macro-process)
. Pending updates
.
.

本章需要了解的概念以及他们的作用:
1 IP地址,子网掩码,网关,DNS服务器IP地址,MAC地址
2 集线器,交换机,路由器
3 ARP缓存表,MAC地址表,路由表
4 互联网中两个主机之间通信时,以上概念在通信过程中作用和所担任的角色

这里啰嗦几句。有时候我们去记这些概念总会忘。主要还是没有深入了解他们的作用。
比如客户端给服务器发送请求。需要什么,需要目标IP地址(ip+端口号)和目标主机MAC地址。
为什么会需要IP地址和MAC地址?
1 通过目标IP地址能找到目标主机所在的子网络(局域网)
2 通过目标MAC地址(物理地址,写在网卡bios上)可以在目标子网络中找到目标主机
3 通过端口号可以在目标主机上找到目标进程(服务)

所以只有真正理解了概念在当前系统中所担任的角色和作用,才会真正的记住她。

This chapter explains the communication process between two hosts through two scenarios. Two hosts in the same local area network communicate; two hosts in different local area networks communicate .
The idea of ​​this chapter
1 The configuration and hardware involved in the communication between two hosts (in fact, all communication in the Internet will be involved)
2 The macro process of sending data packets from one host to two hosts

Insert picture description here

1. The configuration and hardware involved in the communication between the two hosts

Because the communication between the two hosts is explained from a hardware perspective, several concepts need to be involved:

After understanding the role of the following concepts in network interaction, you have a macro understanding of the entire network interaction. Here we have to focus on it.
1 Configuration related

Configuration related:
1) The IP address of the machine : assigned by the administrator, used to identify the logical address of each network or host on the Internet. (The physical address is the MAC address). Through the IP address, you can find the subnet (LAN) where the host is located on the Internet. Through the MAC address, you can find the target host (network card
) in the subnet . 2) Subnet mask : The subnet mask needs to be used in conjunction with the target IP address , Indicating whether the target IP is on the LAN or WAN.
3) Default gateway (IP address of gateway) :
4) DNS server (IP address of DNS) : Domain name system protocol, mainly used for the conversion between domain name and IP address. Knowing the domain name to obtain the corresponding IP address or known IP address to obtain the corresponding domain name.
Insert picture description here
The above picture is a computer network related attribute configuration diagram. Whether it is dynamic (automatic) acquisition or static setting, the above four attributes are indispensable for computer Internet access.

2 Hardware related

Hardware related:
1) Host : personal computers, servers, printers and other devices with network cards.
2) Switch : responsible for communication between different hosts in the same subnet, and forwards data frames according to the MAC address table. Purposeful forwarding or broadcasting
3) Hub : Responsible for communication between different hosts in the same subnet, broadcast data frames according to the MAC address table. Only broadcast
4) Router : responsible for communication between different networks.

ARP protocol : address resolution protocol, known target ip address to obtain target mac address

ARP cache table MAC address table Routing table
Working level Network layer data link layer Network layer
Work equipment Host computer (and router) switch Router (and host)
effect Correspondence between IP address and MAC address Correspondence between Mac address and interface Record information to different network segments

The following two figures are used to facilitate the understanding of the location of the host ARP table, MAC address table and routing table in the network framework, the corresponding equipment and the corresponding working level. In fact, there is also a routing table on the host and an ARP table on the router.

Insert picture description here
Insert picture description here
Here are the first concepts to summarize. In the end, what is the role of
1 IP address, mac address, subnet mask, DNS server address, and how does it work?
2 What role do switches and routers play in network communications?
3 What is the role of ARP cache table, MAC address table and routing table in network communication?
The last section will explain in detail.

Summary
ARP cache table :
records the correspondence between IP addresses and MAC addresses of other hosts in the LAN.
.
MAC address table :
records the correspondence between MAC addresses and interfaces.
.
Routing tables :
record a sub-network to another sub-network path. Destination IP address, next router address, netmask, etc.

To summarize the
router :
1 Connect to different subnets in the Internet.
2 Realize data forwarding between different sub-networks in the Internet.
3 Assign IP address
.
Switch (unicast or broadcast) and hub (broadcast) :
1 Connect different hosts in the LAN.
2 Realize data exchange between different hosts in the LAN.
3 Distribute network data

Summary
1 DNS :
Domain Name System Protocol, mainly used for the conversion between domain names and IP addresses. Knowing the domain name to obtain the corresponding IP address or known IP address to obtain the corresponding domain name
2 ARP protocol :
address resolution protocol, known target ip address to obtain the target mac address


Two two host communication process

Referring to the above figure, the network communication between the host and the host in the Internet is nothing more than the following two situations. Only described herein macroprocesses client sends a request to the server (the server returns a response process packets as)
within a same sub-network host communications: subnet A in the host A , the sub-network A in the host B sends data packets during
two different sub-network host communications: subnet a in the host a , the sub-network B of the host a transmits a packet process


When host A sends a data packet to another host, it will first get the IP address of the target host (you have to ask how to get it, embedded in the web page, the app is written in the code or obtained by request, etc.)

1 If our request address is in the form of a domain name, we need to first request to DNS服务器obtain the corresponding IP address.
2 Host A will use the machine to configure 24 bits 子网掩码and 目标IP地址perform an AND operation (the specific calculation process is consulted by yourself). Calculate whether the target IP and the machine are on the same network segment (within the same LAN).

1 If they are in the same network segment: host communication in the same sub-network (the following figure shows the communication between host A and host B as an example)

Insert picture description here
There are two cases. In the ARP table of host A, the MAC address of the target host can be found and the MAC address of the target host cannot be found:

Case 1:
1 Host A queries ARP表(target IP and target MAC address relationship table). If the MAC address of target host B is found, send a data frame.
2 After receiving the data frame, the switch first records the source mac address and the corresponding interface (the interface is f 0/1) ( 这个过程主机A的MAC地址就被记录到交换机 MAC地址表中了,下次有其他主机发送数据包到主机A,可以直接查询MAC地址表,通过MAC地址就直接找到主机A对应的接口,从而能和主机A直接通信了).
3 Check MAC地址表whether there is mac information of the target host B. If there is a data frame sent out (unicast)
4 Host B will respond after receiving the broadcast
5 The switch receives the data frame and records the source MAC address in the data frame (also It is the MAC address of host B). At this time, when host A and host B communicate, the switch MAC地址表realizes unicast according to the record in it.

Case 2
1 Host A query ARP表(target IP and target MAC address relationship table), if not queried, send ARP request
2 If not queried mac地址, send ARP request (ip is target host ip, mac address is broadcast frame FF-FF- FF-FF-FF-FF)
3 When the switch receives the broadcast frame, it will broadcast in the sub-network (outside the sender)
4 Host B receives the broadcast frame, checks whether the IP is its own, and records the ip and mac address of host A, Send an arp reply (including your own mac address) ( 这里在同一网段内除了主机A的所有主机,主机B,主机C,主机D都会收到广播帧,但是只有主机B会处理)
5 Host A receives the reply and records the IP and MAC addresses of Host B in its ARP cache table
6 and the switch has learned the MAC addresses of Host A and Host B at this time Now, unicast is achieved.

Summary:
When two hosts are connected in the same network segment, if there is a correspondence between the IP address and MAC address of host B in the ARP table of host A, only a request for sending a data packet is required; Relationship, you need to send an ARP request to obtain the MAC address of host B, and then send a packet request.

2 If it is not in a network segment: host communication in different sub-networks (the communication between host A and host A in the following figure is an example)

Insert picture description here
As shown in the figure above: When
not in the same network segment, Host A sends a data packet to Host A, you need to know the IP address and 网关MAC address of Host A

A host computer 1 by ARP协议acquiring 网关MAC地址or local host A manual configuration 网关. At this time, there is the IP address and MAC address of the target host. Host A will update the local ARP cache table
2. Use the IP address and MAC address of host B to send data packets.
3 When the switch receives the data packet, it will update the MAC address and interface of Host B to the MAC address table.
3 The data packet passes through the switch of subnet A to the gateway, and then to the router. After various forwarding, the router finds subnet B where host B is located. ( 现在通常指的网关就是路由器的IP)
4 When the switch in subnet B receives the data, it will query the MAC address table.
5 The relationship between the MAC address of host B and the interface is queried. Data is forwarded to Host B
6 Host B will update the local ARP cache table and record the IP address and MAC address of Host A.
7 The packet response process is the same as the sending process

Summary:
If the above understanding is too cumbersome,
we cannot distinguish whether the message object to be sent by host A is on the same network segment as host A.
1 Host A sends a message to the target host.
Case 1:
2 Query the local ARP cache table, and find the IP address and corresponding MAC address of the target host, and then perform data transmission.
Case 2:
2: If not found, host A will broadcast an ARP request packet ( 无论是从同一网段下的目标主机获取到的MAC地址,还是从从路由器获取的网关地址), obtain the MAC address of the target host ( 也可能是网关地址), and update the local ARP cache table. Then the data is transferred.
3 The subsequent transmission process is not described as above.

Published 15 original articles · Like 28 · Visit 120,000+

Guess you like

Origin blog.csdn.net/qq_27096221/article/details/105650754