4

Newbie here. I'm trying to understand how hubs and switches work. I read that hubs only forwards to all ports but a switch only forwards to the port it needs to.

So, If I connect 3 computers to the same hub, and use PC1 to ping PC2, then all the 3 computers will receive the ping?

But if I connect 3 computers to the same switch and used PC1 to ping PC 2, then only PC1 and PC2 sees the ping because switches only forward it to the correct port. Is that correct?

  • Does anybody actually use hubs anymore? (I mean besides my co-worker, who installed them because he could get them dirt-cheap from an electronics recycler.) – Mark Feb 6 at 23:10
  • Hubs are useful for Wireshark and the like, where promiscuous mode sniffing of a common broadcast domain is desirable. – mckenzm Feb 7 at 2:34
6

If I connect 3 computers to the same hub, and use PC1 to ping PC2, then all the 3 computers will receive the ping?

PC2 and PC3 receive the echo request, and PC1 and PC3 receive the echo reply. A sender's signal is repeated to the other ports but not back the sender.

However, receive depends on the point of view: since the echo request doesn't address PC3's MAC, its NIC physically receives the frame but drops it right away - the encapsulated packet isn't received by the IP stack.

But if I connect 3 computers to the same switch and used PC1 to ping PC 2, then only PC1 and PC2 sees the ping because switches only forward it to the correct port. Is that correct?

Yes. Ping uses IP and IP requires ARP before sending an IP packet (containing an echo request or anything else). ARP causes the switch to learn PC1's and PC2's MAC addresses, so the switch forwards the frames with the echo request/reply to just the intended destinations.

  • 1
    What if its the first time that it is being pinged on the switch, as the switch wont have the Mac Address, so does PC3 also receive it too? – The_Bear Feb 6 at 20:29
  • @The_Bear Yes, when a switch encounters a new MAC address destination, it floods all the other ports and waits for a response. – Veskah Feb 6 at 22:34
3

A hub is simply like a powered cable, where every signal is repeated out all the other interfaces.

A switch is really a high-density bridge. The simplest switches will learn which devices are on which interfaces, and they will then forward frames for a particular device to the interface where the devices is connected. Although, a switch will flood broadcast, and unknown unicast frames out every other interface

Hubs (layer-1 devices) repeat every signal, even garbage, but switches (layer-2 devices) work with frames (dropping damaged frames).

  • So I'm right in saying that if I connect 3 PC's to a switch and use PC1 to ping PC2, only PC1 and PC2 will see the ping, PC3 won't? – The_Bear Feb 6 at 18:25
  • 1
    If the switch has not yet learned the destination interface, it will flood the frame to all the other interfaces. It learns very quickly because it only takes one frame from a host for it to learn where the host is. – Ron Maupin Feb 6 at 18:31
  • So does that mean when the ping is first sent, all the ports will receive it in the switch but if it is pinged again it will only go to PC2? – The_Bear Feb 6 at 20:21
  • 1
    Maybe. As @Zac67 points out, the source host may need to ARP for the destination address, and that will suffice to populate the MAC address table, but the table entries do time out, so it may need to happen again. A host will maintain an ARP table for destinations, and its entries also time out, but that is not coordinated with any other host or the switch MAC address table. You cannot say at any given time if a switch MAC address table has an entry for the destination. – Ron Maupin Feb 6 at 20:53
  • No. The previous ARP already updates the switch's MAC table, so the first ping already goes to PC2 only. – Zac67 Feb 6 at 20:53
2

Ethernet has evolved over time, and has some archaic standards that no longer matter all that much.

Originally Ethernet used what was known as a half-duplex signalling standard, which is like having a 1-lane road with vehicles that can travel in either direction on it.

When endpoint devices try to transmit at the same time on a half-duplex hub network, this causes a collision event, which requires both devices to pause for a random period of time and try again. The official name for how this works is Carrier Sense, Multiple Access, with Collision Detection (CSMA/CD).

https://en.wikipedia.org/wiki/Carrier-sense_multiple_access_with_collision_detection

A basic hub will typically have a single LED indicator to show when a collision has been detected. Some of the more expensive early hubs from the 1990s such as from Cabletron had a collision light for every individual port, that could be used to locate where collisions were happening the most often.

As more devices are added to a half-duplex hub network, the risk of data collisions increases, and overall throughput declines because so much time is being wasted by colliding, waiting, trying again, colliding, waiting, trying again..

Generally an Ethernet cable cannot be longer than 100 meters, and there cannot be more than 4 hubs between two devices, because 500 meters is the distance limit of the collision detection system when two devices try to transmit at the same time but their data packets collide.

,

It used to be that hubs were the inexpensive network component while switches were really expensive, because a hub isn't really much more than a collection of amplifier circuits while a switch includes actual processing to decode and analyze packets, and also splits the collision domains into separate territories.

Though it also used to be that you had to use a special cable called a crossover cable to interconnect endpoint devices or to make hub-to-hub connections. We don't care about any of this anymore because all devices include a way to make any connection a normal or crossover, known as Auto-MDIX.

,

Since some time around 2005, the bottom fell out of the switch market, and switches became cheaper and cheaper until we reached a point where hubs basically disappeared and we now use switches for everything.

The original design spec for 100 meter cables and 4 hubs per collision domain still exist, but it's now basically irrelevant because hubs are no longer in use. We now effectively have an isolated collision domain between every endpoint and its matching switch port.

Due to this you could probably make a half-duplex twisted pair Ethernet cable 500 meters long between a device and a switch port, and it would work fine. Doing this violates the cable length of the original signalling specification which cannot imagine hubs not being used, but 500 meters is compatible with the original half-duplex collision detection method, should the switch port and endpoint device both transmit and collide.

,

But even the collision domain has become irrelevant, due to later twisted pair wiring standards changing from half-duplex to full duplex. What this means is that there is now an isolated path available for sending from one end to the other, in both directions.

In this configuration, a collision is not even possible when a single endpoint connects to a single switch port, and so a twisted pair cable could likely far exceed the 500 meter limit of the collision detection mechanism, and still work.

Though we are now deviating quite far from the original Ethernet design specification and we will instead start running up against electromagnetic limits with capacitance and inductance causing signal degradation.

  • "collision light" - lol, good times - this belongs on Retro.SE – Mazura Feb 7 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.