The principle of network communication between computers in the same local area network and in different local area networks

Hardware network card: It is used to allow the computer to communicate with the computer for self-checking, and to allow the computer to connect to the network


1. The application generates data. At the application layer, there is an application header plus a user data package to encapsulate it into a package.

2. Then pass it to the transport layer. The transport layer is port-to-port, point-to-point, and encapsulates the original port target port and application data at the transport layer.

3. Down is the network layer. The network layer is to add an ip header to the header, and then put the encapsulation of the upper layer in the data part to complete the encapsulation at the network layer.

4 Further down is to add an Ethernet header to the package encapsulated in the previous layer at the layer with Ethernet.

5. When reaching the other party, the other party first transmits the packet from the physical layer to the data link layer, removes the Ethernet header at the data link layer, then hands it to the network layer to remove the ip header, and then hands it to the transport layer to remove it port, and finally passed to the application.



Computer communication relies on mac addresses.

The process of sending the package by computer:


Here is the network segment used to determine whether two computers are in a local area network (broadcast domain)

The following is messaging that is not in a broadcast domain:



1 Message delivery that is not in a broadcast domain needs to be implemented through a gateway.

01. After calculating that it is not in a broadcast domain (judged by the network segment), use the arp protocol as shown in the upper right corner 1 of the above figure: encapsulate the original mac to match its own gateway mac original ip gateway ip and then the gateway of the local area network where you are located gets this packet The gateway will Return your own mac address to pc1

Then the arp protocol is used to send packets based on Ethernet as shown in Figure 3 above: The packets sent by pc1 are broadcast in their own local area network. Because the mac of the gateway is written in the header, the gateway will receive it, and the gateway of pc1 will also have a broadcast here (to the outside). All gateway broadcasts), the target gateway judges whether it is the local area network where it is located by the first three network segments of the ip address, and leaves the packet, and then the target gateway broadcasts the packet in the local area network where it is located. Because there is still the ip address of the target pc3 in the package, pc3 will receive it.

Finally, when pc3 receives the packet from pc1, it will go through all the above processes until it finds pc1, just like the previous pc1 passed to itself. The process is as follows: first determine whether the target ip and itself are in a local area network, if they are broadcast directly through the mac address. If not, first contact the gateway of your own local area network to obtain the mac address of the gateway, and then contact your own gateway with the external gateway (through the following package: the mac address of the pc, the mac address of the own gateway, the ip of the original pc, the ip data of the target pc part), and then the external gateway will disassemble the package and find that the ip of the target pc is in the same local area network as itself, and will let the package stay and broadcast in its own local area network until the target ip is found and the target pc is found.



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326842131&siteId=291194637