HCIA switch principle and ARP protocol

1. Overview

Switch (Switch) is a very important and basic device in network communication. Common information often focuses on introducing a certain point or explaining a certain term. This article tries to understand switching and switches from the perspective of users, but it is limited to HCIA The level, which is relatively shallow, but I hope it can be more comprehensive and practical.

2. Exchange

In fact, from the name, we can roughly know that the function of the switch is to "transmit" data in the network, and it is "transfer" without restriction by default, but the word "transfer" is more inclined to one-to-one transmission, and the switch is Many-to-many transmission, so the name of the switch is very good.

Common switches generally have many ports, such as 24 ports and 48 ports. The purpose is to connect as many devices as possible to achieve intercommunication.

1. one to one

Assuming that there are two computers that need to communicate now, we only need a simple "direct connection", as shown in the figure below. After configuring the IP of the PC, you can directly communicate with each other.

 

2. many to many

But it is impossible for us to have only two computers in our work. For example, there are at least three or five people in an office. What should we do if each person has a computer. A long time ago, there was actually a solution that was a "hub", as shown in the figure below.

The characteristic of the hub is that the data received by each port is forwarded to other ports. In fact, it is also possible for small-scale applications or one main device to only receive data from other devices. But if the network is relatively large, or there are many applications, and a large number of PCs need to communicate with each other, then things like hubs will definitely not work. Since communication is limited by the bandwidth of the ports, the hub would be too busy if every signal was forwarded to all ports.

What would you do if you were asked to modify it based on the characteristics of the hub? In fact, it is easy to handle. I will number the PCs (that is, MAC addresses), and at the same time let the hub "remember" the MAC addresses of the PCs connected to each port, won't the problem be solved? For example, as shown in the figure below, if the device remembers the correspondence between the MAC address and the port, when PC6 sends data to PC9, the device knows that it only needs to forward it to E0/0/4. The switch is actually such a principle.

So what if the ports of a single switch are not enough, it doesn’t matter, they can be connected in series, as shown in the figure below. According to the MAC address and port correspondence table, if PC6 sends a packet to PC11, it only needs to follow this path: E0/0/5 of LSW5 -> E0/0/3 of LSW6 -> E0/0/1 of LSW7.

The question now becomes, how to maintain such a MAC address table in the switch? That is the ARP protocol.

3. ARP protocol and ARP table

Consider the following network structure, what should PC1 do if it wants to communicate with PC2?

For PC1 it knows the following information:

1) Own IP

2) Own MAC address

3) IP of PC2 (target)

At the same time, it also knows that it is connected to the switch. So when PC1 needs to send data to PC2 and it doesn't know more information, it can send a broadcast packet to the switch to "ask" who is PC2 (through the target IP). We know that broadcast packets can be forwarded to all ports of all devices in the network, so if PC2 exists, it must be able to receive it, as shown in the figure below.

When PC2 receives the ARP broadcast, all switches in the network also receive it, even including PC3, so all PCs in the network can make the following records:

The MAC of 192.168.0.11 is equal to 5489-9893-0811

After PC2 records the above information, it needs to respond to PC1, so it will send an ARP response message to inform PC1 of its own MAC address, as shown in the figure below.

In this way, each PC can generate the following ARP table:

PC1:

PC2:

PC3:

Then I don’t know if you have noticed that the ARP table of PC3 only has the MAC of PC1 but not PC2, that is, the ARP message sent by PC1 is a broadcast and the response message sent by PC2 is not a broadcast. The reason is that not only the PC is recording the MAC address in the network, but also the switch is recording the MAC address. Because of the record of the switch, it can send the response message from PC2 back to PC1 without broadcasting.

Four, ARP and MAC table

We said earlier that PC1 only knows the target IP and does not know anything else, so it needs to send an ARP broadcast to the network to ask the target if you are there, and also inform all devices in the network of its MAC address and IP. This includes switches, so each switch can make the following records.

When PC2 responds to the ARP packet, each switch can add another record as follows.

In this way, in addition to the ARP table that can be recorded by the PC, the switch can also record the MAC address tables shown in the figure below.

LSW3:

LSW2:

LSW4:

In this way, according to the ARP table of the PC (correspondence between IP and MAC) and the MAC table of the switch (correspondence between port and MAC), data can be efficiently transmitted between PCs.

5. Message transmission

Assume that the PCs in the network have completed the ARP table, and the switch has completed the MAC table.

PC1 needs to send a message to PC2, and this message only needs to know the IP address, because the ARP table of PC1 has the MAC address of PC2, and the network card will automatically put this information into the message and pass it to LSW3. After receiving the message, LSW3 can query its own MAC table and find that the destination MAC is from E0/0/1, so it will pass the message out through E0/0/1 port, that is, to LSW2. Similarly, LSW2 queries the MAC table and knows that it needs to deliver the message to E0/0/2, so the message is delivered to LSW4. LSW4 checks the MAC table and knows that the target MAC is on its own E0/0/1 port, it just needs to pass it directly, so PC2 receives the message from PC1 in this way.

6. Review

In this article, we have learned about the working principle of the switch, and the ARP protocol, ARP table, and MAC address table that are closely related to the switching function.

Common commands:

Query the ARP table on the PC: arp -a

The switch queries the MAC table: display mac-address

Guess you like

Origin blog.csdn.net/weixin_40402375/article/details/127482866