DEV Community

Cover image for Networking Basics: Part 2 - WHAT IS A SWITCH???????
Bhavesh Yadav
Bhavesh Yadav

Posted on

Networking Basics: Part 2 - WHAT IS A SWITCH???????

In the vast realm of computer networks, understanding the fundamental components is crucial. In our previous blog post, we explored the essence of networks and their significance. Now, it's time to delve deeper and unravel the mysteries of network switches. So, fasten your seatbelts as we take you on a journey through the layers of connectivity!

So without further ado lets get started!

What is a Switch?

Image description

This is how a switch looks like i know its beautiful, this is a 24 port switch by CISCO and yes ports are the holes you can see and you can count them it really has 24 ports, and you can connect ethernet cable to each one of them to create a network of 24 people. This small switch can handle it all. Just saying there are even 48 port switches so just go to internet and search for them you'll love them.

At the heart of any modern network lies a device known as a switch. 🌐 Think of it as a traffic controller, intelligently directing data packets to their intended destinations. Unlike hubs that blindly broadcast data to all connected devices, switches operate at the data link layer (Layer 2) of the OSI model, making them more efficient and secure.

I know i know thats not easy to understand especially you are just getting started, just so many terminologies like switch, data packets broadcasting, data link layer OSI model blah blah blah. But no worries my folks i'll explain each and every thing to you in detail.

Now suppose for example, You have a group of friends(here i refer each friend is sitting in front of a computer) and you all are connected through some device which is handling connections between you guys and if you want to send a message to a specific person you just send it and that person receives it and that device is just called a switch thats it, it was that easy and you might be thinking what special is that device doing. For understanding why switches are so intelligent you need to understand its predecessor i.e. the stupid `HUB.

Now lets understand what a HUB is with an example. Now suppose the same example but now when you send a message then that message is broadcasted to everyone in the group and every computer in the group checks if the message was intended for it or not and if it was intended the message it simply just receives the message otherwise like a good computer it will ignore it. But as you know we live in a digital era and not all persons are good, it might be the case that there is a hacker who just wants to get all the data and do his job which is threaten people. Thats the main reason HUB is called a stupid device and SWITCH is called an intelligent device.

A Switch intelligently sends the message to only that person for whom the message was intended and not to every person on the network.

I hope my this way to explain things is good, if you think so then do tell me in the comments below.

CAM Table

Ughhhh another terminology, But trust me this one is so easy and this is the reason why we call SWITCH intelligent.

Image description

This is how the brain of a Switch aka CAM Table looks like. It has ports named Fa0/1, which are just ports on a SWITCH where you can connected ethernet cables for connection.

A CAM Table is nothing more than a brain of a SWITCH. This is the place where all the MAC addresses are stored. Yeah i know we haven't talked about MAC addresses yet but MAC addresses are nothing more than a unique identity of a device. Every single device in the world has a MAC address and its unique for every device. You can see MAC address of your router, your mobile and literally every device. So this MAC address is the thing through which a Switch confirms that this is the device i have to send the data to.

Now lets see what is the actual definition of CAM Table,

A CAM (Content Addressable Memory) table, also known as a MAC (Media Access Control) table or forwarding table, is a fundamental component of a switch. It plays a crucial role in the efficient forwarding of data packets within a local network.

Just understand it this way, When a switch receives an incoming frame, it examines the source MAC address of the frame. The switch then updates its CAM table by associating that MAC address with the port on which the frame was received.

Yeah i know i question will come to your mind what are this frames and why sometimes we call it a frame and sometimes a packet. So in real world we often call it a packet. But the difference is everything a switches deals with are called frames every electrical signal a switch gets is called a frame and for me just memorize this that this in layer 2, yeah i know we haven't discussed what layers are yet but please bear with me and learn this that switch lies in layer 2 and it deals with frames, yeah thats good say it one more time, switch lies in layer 2 and it deals with frames. Very very good!

Now so what are these packets, packets are nothing just frames with IP addresses and again i know we haven't discuss IP addresses yet and trust me that part will be great one to discuss, In real life people don't care much about this and call everything a packet but fundamentally its different but no one cares, neither will you when you will complete this series and become good at networking.

Also just a little bit of information MAC addresses are also known as Level 2 addresses and IP addresses are also known level 3 addresses.(Remembered this after i finished writing this blog!!!!!!!!)

There can be one more question crawling in your mind, that suppose connection just established and the CAM table is empty then how it gets the MAC address of the destination device. I'll answer it in the next blog, because it includes few more things in it(if you can't wait then just search for ARP packets).

There are two phases in which a CAM Table operates:

Learning Phase: When a switch encounters a new MAC address, it learns the association between the MAC address and the port from which the frame arrived (Ports are nothing just the port through which you entered the ethernet cable). The MAC address is added to the CAM table as an entry, and the associated port information is stored.

Forwarding Phase: In this phase. When a frame arrives at the switch, it examines the destination MAC address(how? i will tell you in next blog). The switch cross-references the destination MAC address with its CAM table to identify the target port for forwarding the frame. Then the frame is forwarded only to the specific port associated with that MAC address.

I know that can be a bit overwhelming but it is how it is, just read it twice and you'll grab it and if you have any doubts then feel free to comment.

Also if you don't get this part just skip it i'll deeply explain this in the next part.

Layer 2 and MAC Addresses

Now lets understand a little bit about layer 2 and MAC addresses a bit.

Layer 2, also known as the data link layer, handles the organization and interpretation of data packets(call it whatever you want just know the fundamental differences) between adjacent nodes(nodes are simply computers) on a network.

This layer is governed by Media Access Control (MAC) addresses, unique identifiers assigned to network devices(just like i said every device has one). When a switch receives a data packet, it examines the destination MAC address to determine which port to forward the packet to, ensuring efficient delivery within the local network.

Conclusion

I know this part can be a bit overwhelming as well as interesting so why are you waiting yet just go and check the mac addresses of your router, written on back of it and i promise you'll feel good. In this blog i just touched the tip of the iceberg and trust me so many interested things are coming in our way and i'm sure you'll find them interesting if you a a nerd like me.

Also i thought why not give you guys a little surprise, so i decided that at the end of this blog series, which will take a while huhhhhh, i'll tell you how you can have a home server and not just a regular one you can host your own personal entire netflix in which you will be able to see movies on your local drive in a good and to simply say netflix like format (shhhhhh If you can't wait till then then try to do a little research on PLEX Media Server).

Top comments (0)