How Switch Works? How Does It Learn MAC Addresses?

In today’s computer networks, switches are super important. They help PCs talk to each other really well. Thus, switches use MAC addresses to send data packets.

In this article, we’ll look at how a switch works. We’ll see how they learn MAC addresses. Also, we’ll check out network packets using GNS3 and Wireshark.

How Switch Works?

How Do Switches Work in a Network and Learn Mac Addresses?

Switches are devices that we widely use in the network and provide data transfer according to MAC addresses.

These devices use the MAC address. In this way, it keeps all the devices you connect to them in its database. It also backs up your devices’ IP addresses. Therefore, Switches act according to the data in their table. So, it looks at its records for fast data transmission.

Let’s say there are two computers on the network. For example, PC1 pings PC2. When pinging, the ICMP protocol assigns source and destination IP addresses on the fly.

Then, since PC1 does not know PC2’s MAC record, it broadcasts a message to the LAN. The type of this message is Broadcast. It notifies the network using ARP (Address Resolution Protocol).

PC1 sets the target part to ff:ff:ff:ff:ff:ff for Broadcast. In short, PC1 asks who owns the IP address 192.168.5.10 using the ARP protocol. For this, ARP finds the device with 192.168.5.10. Then, in the next step, you perform the ping operation.

In our previous articles, we talked about what a switch is and the types of switching. Without going into further detail, I know you are knowledgeable about the relevant topics. So, now, let’s examine how this device learns MAC addresses on a network.

How to Examine the Operating Logic of a Switch using Wireshark in GNS3

Once we’ve set up a simple network using GNS3, we’ll ping from PC1 to PC2. But before we ping, we’ll use Wireshark to analyze the packets between PC1 and the Layer 2 Switch.

Please follow the steps below to examine how a Switch works.

Step 1

To begin with the GNS3 simulator, locate and open the software. After opening it, create a new project. Then, specify the project’s details in the new window.

Creating a New Project in GNS3

Step 2

Add one Layer 2 Switch and two VPCS to the GNS3 workspace. For example, define an IP address block and add comments to the workspace.

Adding L2 and VPCS for Switch Operating Logic

Step 3

Assign IP addresses to VPCS computers. Later, use the show ip command in the command prompt to verify this action.

VPCS / show ip

Step 4

The IP information on PC2 is as follows. In the meantime, remember the ethernet addresses of PC1 and PC2.

Using VPCS / show ip command

Step 5

Since there is no data transaction on the network, the ethernet address table on the Switch will be empty. To verify this, you can use the show mac address-table command to see the result.

Sometimes, computers send ARP Broadcasts. This helps them create their tables. Therefore, the Switch keeps MAC addresses in its cache for about 10 minutes. So, from now on, they no longer need to make ARP broadcasts to send more packets.

show mac address-table

Step 6

To start Wireshark in GNS3, first, make a connection. Then, click “Start Capture” on that connection. This starts grabbing data packets so you can watch and analyze the network traffic.

Running the Wireshark Program

Step 7

Click the “OK” button in the Packet Capture window to keep analyzing data.

Making Packet Capture with Wireshark to Understand How Switch Works

Step 8

As soon as you press the OK button, the Wireshark program will automatically open. You will then see it start performing packet analysis in the image below.

Controlling Data Flow Between Switch and PC on Wireshark

Step 9

When you ping from PC1 to PC2, Wireshark captures ARP protocol activity.

Examining the Switch's ARP Protocol Usage

Step 10

Click ARP Broadcast for more information. As in the image below, PC1 will broadcast to the target address ff:ff:ff:ff:ff:ff because it does not know the IP of PC2 yet.

Consequently, ARP Broadcast reaches the MAC of the PC with the IP 192.168.5.10. Now PC1 knows PC2’s ethernet address. As a result, you will see that ping (ICMP) starts without any problems.

ARP Broadcast

Step 11

Review ARP address resolution by clicking column 25 in Wireshark. Also, note that the source and destination address spaces are PC1 and PC2.

Sender MAC Address

Step 12

If the ping process is ok, then use the show mac address-table command on the Switch. Now, you will be able to see the device table here. As a result, you can see that the addresses PC1 and PC2 are in the table.

Checking the Switch's MAC Address Table

Step 13

If you want to delete table records, you can do this by using the clear mac address-table command.

Clearing the Switch's MAC Address Table

Step 14

You can also see the address records on VPCS PC1 and PC2. You can use the show arp command to do this and the clear arp command to delete it.

clear arp

Step 15

And finally, click on Stop Capture to close the Wireshark packet analysis program on GNS3.

Stop Capture

How Does a Switch Find MAC Addresses? > Table

Network Switch Operations
StagesExplanation
1. StageThis is the first time you have connected a device to a switch. At this point, the Switch has no information about that device.
2. StageThe device sends a frame to the current network with the source MAC address.
3. StageThe Switch gets the frame. It then checks the source address in the MAC address table.
4. StageIf the source address is not in the table, this time, it adds the frame with the port to the table.
5. StageLet’s say the source address already exists in the table. The Switch then updates the port information for that MAC.
6. StageThe Switch receives a frame with the destination MAC address. And immediately, it looks up the target address in its table.
7. StageIf the destination address is in the table, it forwards the frame by forwarding it to the correct port.
8. StageIf it doesn’t find the destination in the table, it sends the frame to all ports except the one it got it from.
9. StageAs the devices communicate, they learn the association between IDs and ports. As a result, it updates the ID table accordingly.

How Switch Works ⇒ Video

To learn how Switches learn MAC addresses, you might find the video below helpful. Also, if you want to support our work, please consider subscribing to our YouTube channel. Thanks!

Frequently Asked Questions About Switch Working Logic (FAQ)

  1. How does a Switch work in a network?
The Switch connects multiple computers, such as printers and servers. It does this within a local area network, i.e., LAN. Thus, all the devices you connect will communicate with each other. Technically, it operates at the data link layer of the OSI model. It uses MAC addresses to locate devices and transmit data packets. In short, it acts like a traffic cop directing data where it needs to go.
  1. How does a Switch do its job?
For example, you have a device connected to a Switch. It reads the MAC address of this device. It then checks the routing table to determine the destination address. If it doesn’t find anything in its table, it broadcasts to all devices connected to it. It then finds the physical ID of the target and saves it in its table. In this case, wherever your device wants to go, it uses the records in its table and forwards them to the destination.
  1. How does a Switch send data?
Switches transmit data packets based on the physical ethernet address, of course. If it receives a data packet, it searches for the ID, reads it, and saves it. If it has a record, it directs devices to the target. As a result, if it does not have a record, it sends data by broadcasting. In short, it acts like the police to devices by preventing congestion on the network.
  1. How do the Switches get on the Internet?
These appliances do not connect directly to the Internet. Instead, they connect to the router one by one. The router connects the LAN to the Internet. It then allows devices connected to it to access online resources.

Conclusion

Think about setting up a Static address for better network performance. This cuts down on ARP Broadcasts and helps reduce congestion. You can also check the record table in Windows using the “arp -a” command.

To summarize, it is essential to really know how switches work in networks. They use MAC addresses to send data efficiently. Moreover, understanding how switches learn ethernet IDs helps with fixing problems and making things run better.

By using tools like Wireshark in simulated networks, admins can look at packets. This helps them understand how they work. Following good practices, like setting static records and keeping an eye on tables, makes sure everything runs smoothly.

Add a Comment

Your email address will not be published. Required fields are marked *