Understanding Hubs, Switches, and Routers: From Physical Layer to Network Layer
This article explains the concepts and inner workings of network hubs, switches, and routers, covering their roles across OSI layers, the differences between them, and how devices communicate using MAC and IP addresses, with practical examples and diagrams.
The story starts with a wheel hub, which shares its name with the networking hub that aggregates cables.
Connecting Two Computers with a Cable
Simply plugging a cable between two PCs does not guarantee communication; the OSI model layers must be considered.
Application Layer
The application (e.g., a game) ensures its own networking functions.
Transport Layer
Most games use TCP; the TCP header contains source and destination ports that identify the processes handling the data.
Network Layer
Each host has an IP address, e.g., 192.168.0.105 . For two hosts to communicate directly, they must be on the same LAN with matching subnet masks, such as 225.225.225.0 , allowing addresses like 192.168.0.105 and 192.168.0.106 .
Data Link Layer
Frames carry a MAC header. A typical MAC address looks like 28:f9:d3:62:7d:31 . The sender must know the receiver's MAC address, which is obtained via the ARP protocol.
28:f9:d3:62:7d:31Physical Layer
Bits are transmitted over a cable. For a direct link, a crossover cable (or auto‑MDI/MDIX capable NIC) is required.
What Is a Hub?
A hub operates at the physical layer, simply repeats incoming electrical signals to all ports, resulting in broadcast traffic.
Internal Structure of a Hub
Signals enter a PHY module, are converted to a common format, passed to a repeater circuit, and then re‑converted for each output port.
What Is a Switch?
A switch works at the data‑link layer, maintains a MAC address table, learns which MAC address is attached to which port, and forwards frames only to the appropriate port, avoiding unnecessary broadcasts.
MAC Address Table
The switch records port‑to‑MAC mappings, ages out entries that become stale, and uses the table to forward frames efficiently.
Special Cases
If the destination port equals the source port, the switch discards the frame.
If the MAC address is unknown, the switch floods the frame to all ports except the source.
What Is a Router?
A router operates at the network layer, using IP addresses instead of MAC addresses. It maintains a routing table to forward packets between different subnets.
IP Addressing
IP addresses consist of a network part and a host part, e.g., 192.168.0.105/24 , where the first 24 bits identify the network.
Routing Table
The router looks up the destination network in its routing table to decide the outgoing interface; if no entry exists, it drops the packet and may send an ICMP message.
Router vs. Switch
Routers have MAC and IP addresses on each interface, can be the final destination of a frame, and perform address translation across networks, whereas switches only forward frames based on MAC tables.
Router vs. Optical Modem (光猫)
An optical modem converts optical signals from fiber to electrical signals for the router; the router then processes the packets and may convert them back to optical signals for upstream transmission.
Summary
Two computers can communicate directly via a cable if all OSI layers are correctly configured.
Hubs broadcast traffic at the physical layer, which is inefficient for many devices.
Switches (layer‑2) learn MAC addresses and forward frames selectively, eliminating unnecessary broadcasts.
Routers (layer‑3) use IP subnets and routing tables to connect multiple networks without maintaining exhaustive MAC tables.
In modern homes, a single router (often with built‑in switch ports) and an optical modem provide all needed connectivity.
Final Note
The author reflects on the evolution from internet cafés to home networking, encouraging readers to continue exploring knowledge.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.