Switch communication process

introduction

The seven-layer network protocol, from bottom to top, is the physical layer, link layer, network layer, transport layer, session layer, presentation layer, and application layer. Among them, the network layer protocol uses IP to distinguish individual physical devices. So how are IP packets forwarded through the switch? Here is an introduction to the general process principle.

1 Scenario example

We assume that there are five PCs with IP addresses from 192.168.1.21 to 192.168.1.25 connected to the switch. Then access to the Internet through the 192.168.1.1 router, that is, the external network. The network structure diagram is as follows:
Insert picture description here
as shown in the figure above, everyone who knows the network knows that: each PC and router need to manually or automatically set the local address, but also need to configure the subnet mask to 255.255.255.0 and configure the gateway to 192.168.1.1 .
Note 1: The data sent and received by each device is not directly sent IP data packets, but IP data packets are encapsulated in MAC protocol for forwarding, so the bottom layer is the MAC address to identify the final device address. The MAC address is generally fixed at the factory and remains unchanged for life.
Note 2: When accessing a certain IP for the first time, the PC does not cache the mapping between the IP address and the MAC address, so it is necessary to query the MAC address corresponding to the IP address through the ARP protocol.
Note 3: The switch has six ports A, B, C, D, E, and F. When it first started, I don't know which port is connected to which IP address or MAC address of the physical device.
Note 4: The device connected to the switch port does not correspond to only one MAC or IP address. Because it can be connected to another switch, the correspondence between the port and the MAC/IP address is one-to-many.

2 Internal network communication

Assuming that 192.168.1.21 sends an IP packet to 192.168.1.22, first judge the same network segment as yourself through the configured subnet mask, and then perform the following process:
Insert picture description here
Note: The above process 1 to 8 is only for the first communication In the process, the MAC address will be queried through the ARP protocol, and the subsequent communication will directly find the MAC through the local machine querying the IP-to-MAC mapping table, and then perform steps 9 and 10.

3 External network segment communication

Assuming that 192.168.1.21 sends an IP data packet to 192.168.3.5, first judge that it is not the same network segment as you through the configured subnet mask, and then perform the following process:
Insert picture description here
Note: The above process is exactly the same as the internal network segment, except that The difference is that it is forwarded to a fixed IP (that is, the gateway 192.168.1.1), and then forwarded to the upper level network by the gateway.

4 summary

Through a general introduction to the communication principle of the switch, it is not difficult to conclude that it is essentially a chain of responsibility mode .

Guess you like

Origin blog.csdn.net/fs3296/article/details/105363102