Network Devices – How Hubs and Switches Work and How to Secure Them (2024)

/ #Computer Networking
Network Devices – How Hubs and Switches Work and How to Secure Them (1)
Omer Rosenbaum
Network Devices – How Hubs and Switches Work and How to Secure Them (2)

In a previous post I described every bit and byte of the Ethernet protocol. In this post you will learn about two network devices, how they work, and how this knowledge may be used by hackers.

Before describing the network devices, consider a network without special network devices. That is, a network using classic Ethernet where all computers are attached to a single cable.

Network Devices – How Hubs and Switches Work and How to Secure Them (3)

In this case, if computer A sends a message to another computer, for instance – B, the message is sent over the shared cable, and all devices receive it.

Network Devices – How Hubs and Switches Work and How to Secure Them (4)

Can you think of some problems with this network structure?

First, overload – all network frames are received by all computers. Let’s say A wants to send a frame to B. C also sees this frame, and has to realize that it is not destined to his address, and thus discard it. This process takes time and resources. The same process happens at machine D, of course.

Second, privacy – if C sees every message sent from A to B and vice versa, this means that the privacy is violated. We would rather have a network where only A and B see the messages sent between them.

Third, extensibility – this network is not really extensible. Assume that up to 10 computers can attach to this cable. What happens when you need to add one more computer? You'd have to replace the entire cable. This is expensive and inconvenient.

Well, the person who actually has to replace the cable is probably the I.T. person - you know, the one who makes sure that everything runs well in your network and is rarely noticed until something bad happens (at least when you work in an organization large enough to have I.T. people).

Just to be clear – we LOVE the I.T. person. We want their life to be good, we don’t want them to be running around buying cables all the time.

Fourth, collisions – let’s say A wants to send a message to B, and C wants to send a message to D. At the same time, both of them might start their transmission, and the messages will collide.

In this case, we get errors – much like the case where two people start to speak at the same time, and it is impossible to understand either of them.

Fifth, this network structure might lead to starvation – let’s say that A is transmitting a frame. If the other stations wish to avoid collisions, they will refrain from sending data. But now, machine A can keep on transmitting forever, thereby taking all the bandwidth to itself and not letting any other station speak. This is called starvation.

Network Devices – How Hubs and Switches Work and How to Secure Them (5)

Well, this doesn’t seem like the best network, does it?

We'll now get to know network devices that help deal with these issues.

What is a Hub?

One device that solves only the extensibility issue is called a Hub. A hub is a device with multiple ports that single Ethernet cables are connected to:

Network Devices – How Hubs and Switches Work and How to Secure Them (6)

So now, instead of having one cable with multiple ports with many computers attached to it, we have instead a single hub, and each computer is connected to it via a single cable. This makes the I.T. person's life much easier.

The hub simply takes the pulse it receives and multiplies it – that is, sends it to all other ports. For example, if A sends a frame to B, the hub will send this frame to B, C and D – all ports except A’s port.

The hub doesn’t understand Ethernet, and doesn’t know anything about MAC addresses. For the hub, all bits are just bits transmitted over the wire, and these bits should get to all other ends.

Network Devices – How Hubs and Switches Work and How to Secure Them (7)

Now, if you need to add a new computer to the network, you can simply connect it to the hub.

Network Devices – How Hubs and Switches Work and How to Secure Them (8)

What happens if the hub runs out of ports? No problem, we will connect it to another Hub, like so:

Network Devices – How Hubs and Switches Work and How to Secure Them (9)

Nice! This is a lot easier to maintain than classic Ethernet.

Yet, at least with classic hubs, all other issues still remain. Since all computers receive the frame sent from A to B, there is no privacy, the network is overloaded, collisions may occur, and the network is prone to starvation.

What we really want is a device that, when A sends a frame to B, forwards that frame to B and only B. This device is called a switch.

What is a Switch?

If all the stations are connected via a switch, and A sends a frame to B, only B receives it.

Network Devices – How Hubs and Switches Work and How to Secure Them (10)

Notice that this means that all issues are indeed solved. The devices won’t be overloaded as every frame will get only to the relevant recipients. There are no privacy issues since, apart from the switch, only A and B see the frame. The network is easily extensible by plugging additional switches if needed.

Network Devices – How Hubs and Switches Work and How to Secure Them (11)

The switch can avoid collisions as every connection between a switch and an endpoint is a single collision domain – that is, the switch will refrain from sending more than one frame on a single wire at the same time.

Network Devices – How Hubs and Switches Work and How to Secure Them (12)

Similarly, there will be no starvation as B and C can communicate with one another while A is sending data. Even if A keeps sending frames destined to the entire network, that is the broadcast address, the switch can allow messages sent by other hosts to be transferred in between.

But, how can this magical switch operate?

Let’s say we have just bought a brand new switch and plugged it into the network. A sends a frame destined to B. How does the switch know where computer B resides?

One option would be to manually configure the switch. That is, have a table mapping between a MAC address and the relevant port, and have someone manually configure that table.

Network Devices – How Hubs and Switches Work and How to Secure Them (13)

When we say someone, we usually mean the I.T. person. And, well, we LOVE I.T. people. We wouldn’t want to make them do this tedious job every time.

In addition, I don’t know about you, but most people don’t usually have an I.T. person at home for every time they plug a device into their network.

Another option would be to send a special message from the switch to every port, and then the endpoints will reply with their MAC addresses. The major downside here is that we now have to make all devices aware of the switch. We need to change the devices’ behavior so they reply to that special message.

It would be so much better if the switch were just transparent – no endpoint would need to know that it’s there, but it would still do the job.

Apparently, this can indeed be achieved!

Consider this network, with a brand new switch that has just been added to the network. The switch stores a table, mapping a MAC address to a physical port. This table is empty.

Network Devices – How Hubs and Switches Work and How to Secure Them (14)

Now, A sends a frame to B.

The switch understands Ethernet, and can look at the Frame’s header and read the source address. Since this source address maps to “A”, and since the message has been sent from physical port number 2, the switch adds the mapping of A’s MAC address and port number 2 to its table.

Network Devices – How Hubs and Switches Work and How to Secure Them (15)

But what will the switch do with the frame? Well, for now, the switch doesn’t know where B resides, so the switch simply multiplies the frame and sends it to all ports, just like a hub would do. So for now, B, C and D all get the frame.

Network Devices – How Hubs and Switches Work and How to Secure Them (16)

Next, A sends another message to B. The switch looks at it, and already knows that A’s MAC address is plugged to port number 2. It still doesn’t know B, so this frame is sent to all other ports as well.

Now, C sends a frame to A. The switch looks at the source address, and adds the mapping between C’s MAC address and port number 5 to its table.

Network Devices – How Hubs and Switches Work and How to Secure Them (17)

This time, since the frame is destined to A’s MAC address, and since the switch knows that address – the frame can be forwarded to port number 2, and port number 2 only. Yay! 👏🏻👏🏻👏🏻

Now, B sends a message to C. The switch creates a mapping between port number 7 and B’s MAC address, which appears at the source address field.

Network Devices – How Hubs and Switches Work and How to Secure Them (18)

The switch can also forward the message to C, as it already knows C's address.

So, in general, the switch uses the source address field of Ethernet frames to dynamically learn what addresses reside behind every port.

Now, a question for you: Is it possible for two different addresses to map to a single port? For example, to have the address of computer A map to port number 3, and also have the address of computer B map to port number 3? 🤔

Well, the answer is yes. Consider the following network:

Network Devices – How Hubs and Switches Work and How to Secure Them (19)

Now, given that the switches know the network, when A sends a message to D, it will be sent to Switch 1, and then to Switch 2, and finally forwarded by Switch 2 to D. When Switch 2 sees the frame, what address does it see in the source address field?

The address of computer A, of course. Notice that switches are transparent, and never modify the MAC addresses. So Switch 2 learns that the MAC address of computer A resides behind port number 3.

Next, when computer B sends a frame to computer C, this message will also be transferred via switch 1 and then switch 2. So now, switch 2 learns that the MAC address of computer B resides behind port number 3 as well. So, in this case, both the MAC address of A and that of B reside behind port number 3.

Network Devices – How Hubs and Switches Work and How to Secure Them (20)

NOTE that a switch is not an additional hop! We are not talking about routing here. As we’ve said earlier, a switch is a transparent device. From the endpoints’ perspective, there is no switch – A “feels” as if it were directly connected to B, C and D.

All devices that are connected via one hop are said to be in the same network segment. So here, all computers and switches – A, B, C, D, switch 1 and switch 2 – all reside within the same segment.

In the resources section below, I’ve added a link to an exercise about hubs and switches. You are welcome to solve it in order to make sure everything is clear. If you have any questions, feel free to reach out 😊

Interim Summary

So far you learned about two network devices. First, a hub, which is basically a first layer device. That is, it only transmits bits from one port to other ports, without understanding any protocols.

Second, you got to know a second layer network device, namely a switch, which already "understands" the Ethernet protocol and MAC addresses. It uses that knowledge in order to transfer frames only to relevant ports, at least once it knows the network.

Now that you understand how hubs and switches work under the hood, it's time to consider their security implications.

Assume that I am connected to a certain Ethernet segment, and you run on computer A. B sends a message to C. Is it possible for you to see that message?

Network Devices – How Hubs and Switches Work and How to Secure Them (21)

In case the computers are connected via a hub, you certainly will see the message, as the hub simply forwards the frame to all ports (except for the source port) regardless of the destination address.

Network Devices – How Hubs and Switches Work and How to Secure Them (22)

Furthermore, if the computers are connected via a switch, but the switch has not yet learned the address of the destination, this message will also be sent to your port – and, in general to all ports other than the source port, just like a hub would act.

Network Devices – How Hubs and Switches Work and How to Secure Them (23)

So, in these cases, your network card will receive the frames, but will it handle them?

As I covered in a previous tutorial, the first field of an Ethernet frame is the destination address. By default, the network card will discard frames that are not destined to its address, or to a group which its system belongs to, such as the broadcast address.

Network Devices – How Hubs and Switches Work and How to Secure Them (24)

So, by default, if your network card happens to receive a frame that was not destined to it, the frame will be discarded. This is exactly where promiscuous mode comes in handy. When the network card is in promiscuous mode, it will not discard frames based on their destination MAC addresses.

Now, consider a network with a switch, and that switch has already learned all addresses of the network, thereby achieving privacy.

Let’s say that a malicious person works from computer C, and wants to see the communication being sent to computer B, even though the switch forwards those frames to B only.

Network Devices – How Hubs and Switches Work and How to Secure Them (25)

Can the malicious person do something in order to steal the data?

Well, the malicious person can pretend that they have B’s address. That is, the malicious person will send a frame with the source address of B. It doesn’t really matter what the destination address of that frame would be.

Network Devices – How Hubs and Switches Work and How to Secure Them (26)

Now, the switch sees a frame being sent from B’s address and from C’s port, in our diagram, port 5, and changes the mapping of B’s address to port 5.

Network Devices – How Hubs and Switches Work and How to Secure Them (27)

As I mentioned earlier, it is indeed possible to have two different MAC addresses map to the same port number (for instance in case of an additional switch that connects the devices that have these addresses). But it is not possible to have B’s address mapped to two different ports.

Network Devices – How Hubs and Switches Work and How to Secure Them (28)

Now, if A sends a message to B, it will actually get to C, but not to B! 😨

This technique is called MAC SPOOFING. The malicious entity is said to spoof B’s MAC address.

Is this technique very useful for the attacker? 🤔

Well, not really. Once B sends any frame at all to the network, the switch will replace the entry for B’s MAC address to that of the correct port number. So, for the attacker to keep receiving data, they will have to keep sending more frames on B’s behalf, thereby causing the switch to rewrite the table entry again and again.

This way, C will send a frame using B’s address, and the switch will map B’s MAC address to C’s port. Then, B will send a frame, and the switch will map B’s MAC address to B’s port again.

Network Devices – How Hubs and Switches Work and How to Secure Them (29)

Hence, B will receive some of the traffic, and this attack is easily noticeable.

There are many ways to defend a switch from such attacks. One would be to set the port with a maximum number of MAC addresses that are attached to it. For instance, if no other switch is supposed to be connected to a certain port, the maximum number of linked MAC addresses can be set to one.

How cool is that?! By understanding how a switch operates, we are able to estimate security issues that stem from its way of operation, as well as relevant countermeasures. 🤯

In this post you learned about two important network devices, a hub and a switch.

You learned that a hub simply multiplies the bitstream it receives to all ports other than the port that received the bitstream, whereas a switch forwards the frame only to the right port (once it has learned the network). You also learned how switches are able to achieve this ability automatically.

Lastly, you learned about a security problem that arises from the way switches operate, and how it may be mitigated.

About the Author

Omer Rosenbaum is Swimm’s Chief Technology Officer. He's the author of the Brief YouTube Channel. He's also a cyber training expert and founder of Checkpoint Security Academy. He's the author of Computer Networks (in Hebrew). You can find him on Twitter.

Additional Resources

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

Network Devices – How Hubs and Switches Work and How to Secure Them (30)
Omer Rosenbaum

Read more posts.

If you read this far, thank the author to show them you care.

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

ADVERTIsem*nT

Network Devices – How Hubs and Switches Work and How to Secure Them (2024)

FAQs

How do hubs and switches work? ›

Switches record MAC addresses in a table to learn which devices to transmit information to. Hubs are less intelligent devices and always send all information to all connected devices. Switches connect devices to a singular LAN to transmit data from one device to another.

What is a network hub and how does it work? ›

In networking, a hub is a device that links multiple computers and devices together. Hubs can also be referred to as repeaters or concentrators, and they serve as the center of a local area network (LAN). In a hub, each connected device is on the same subnet and receives all data sent to the hub.

How do network devices such as routers, switches, and hubs work together to form a network? ›

Whereas a hub forwards the data it receives to all of the ports on the device, a switch forwards it only to the port that connects to the destination device. It does this by learning the MAC address of the devices attached to it, and then by matching the destination MAC address in the data it receives.

What are the connections of switches and hubs? ›

Cables Connecting Hubs and Switches. Two types of cables are used to connect devices to hubs and switches: crossover cables and straight-through cables. The difference between the two types is that in a crossover cable, two of the wires are crossed; in a straight-through cable, all the wires run straight through.

How do network switches work? ›

A network switch is a physical device that operates at the Data Link layer of the Open Systems Interconnection (OSI) model — Layer 2. It takes in packets sent by devices that are connected to its physical ports, and forwards them to the devices the packets are intended to reach.

How does a hub switch and router work? ›

Routers connect multiple networks and determine the best path for data transmission based on IP addresses. Switches connect devices within a network and enable efficient data transfer using MAC addresses. Hubs, on the other hand, simply broadcast data to all connected devices.

What is the difference between a network hub and a switch? ›

A network hub is a node that broadcasts data to every computer or Ethernet-based device connected to it. A switch is a device that channels incoming data from any one of multiple input ports to the specific output port that will take it toward its intended destination.

How does a hub connect? ›

Hub is commonly used to connect segments of a LAN (Local Area Network). A hub contains multiple ports. When a packet arrives at one port, it is copied to the other ports so that all segments of the LAN can see all packets. Hub acts as a common connection point for devices in a network.

What is a switch hub? ›

A network switch (also called switching hub, bridging hub, and, by the IEEE, MAC bridge) is networking hardware that connects devices on a computer network by using packet switching to receive and forward data to the destination device.

How do devices work together in a network? ›

How do they work? Computer networks connect nodes like computers, routers, and switches by using cables, fiber optics, or wireless signals. These connections allow devices in a network to communicate and share information and resources. Networks follow protocols, which define how communications are sent and received.

How do network devices work? ›

A network device is a node in the wireless mesh network. It can transmit and receive wireless HART data and perform the basic functions necessary to support network formation and maintenance. Network devices include field devices, router devices, gateway devices, and mesh hand-held devices. Field devices.

What is a network switch for dummies? ›

A network switch connects devices within a network (often a local area network, or LAN*) and forwards data packets to and from those devices.

What are two main differences between a hub and a switch? ›

Key Difference Between Hub and Switch

A Hub is a networking device that allows you to connect multiple PCs to a single network, whereas a Switch connects various devices together on a single computer network. A Hub operates on the physical layer, whereas Switch operates on the data link layer.

How to link switches together? ›

There are a lot of ways to connect switches. You can daisy chain them, star link them, cascade them, cluster them or stack them. In most modern networks, cascades, clusters, and stacks tend to be more prevalent. That is because they offer specific benefits that many modern network designers find admirable.

What is a major problem with a hub vs a switch? ›

The main problem is bandwidth usage. With the hub constantly sending data to every machine connected to it, hubs use a lot of bandwidth compared to switches. The more devices that are connected, the more the network is flooded with all this data.

What is the purpose of a hub switch? ›

A network switch (also called switching hub, bridging hub, and, by the IEEE, MAC bridge) is networking hardware that connects devices on a computer network by using packet switching to receive and forward data to the destination device.

How does Ethernet work with hubs and switches? ›

Ethernet hubs work much in the same way but can only complete a simple data transfer between connected devices. In contrast, switches offer added layers of security and control over how data is transferred.

When should you use a hub vs a switch and why? ›

If you have only a few devices on your LAN, a hub may be a good choice for a central connection for your devices. If you have the need for more connections, an Ethernet switch may be a better option over a hub.

Why are hubs no longer used in networking? ›

Hubs are not used anymore. As networks grew larger and more complex, the limitations of hubs became increasingly apparent. With all data being broadcast to all devices, network congestion and data collisions became more common, leading to slower data transfer speeds and decreased network performance.

Top Articles
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 5269

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.