Networks are built from devices that connect nodes, extend links and join networks together. Each works at a particular layer.
Hubs and Repeaters
A repeater (layer 1) regenerates a weakened signal to extend the length of a cable. A hub (layer 1) is a multi-port repeater: it receives bits on one port and broadcasts them to all other ports. All devices on a hub share the bandwidth and form one collision domain, so hubs are slow and insecure, and have been replaced by switches. Hubs need no configuration.
Definition: Router. A layer-3 networking device that connects different networks and forwards packets between them, choosing the best path using IP addresses and a routing table.
Bridges and Switches
A bridge (layer 2) connects two LAN segments and filters traffic using MAC addresses: it forwards a frame only if the destination is on the other segment. A switch (layer 2) is a multi-port bridge. It learns which MAC address is on which port, stores this in its MAC address table (CAM table), and forwards each frame only to the port of its destination. Each port is a separate collision domain, and switches support full-duplex operation. A switch floods a frame to all ports only when the destination is unknown or the frame is a broadcast. Managed switches can be configured: VLANs, port security, spanning tree (STP) to prevent loops, and link aggregation. Layer 3 switches can also route between VLANs.
Routers
A router (layer 3) connects different networks, such as a LAN and the internet, and forwards packets using IP addresses. It keeps a routing table of destination networks and next hops, built statically by the administrator or dynamically by routing protocols such as RIP and OSPF. Routers separate broadcast domains, perform NAT, and often act as firewalls and DHCP servers. Configuring a router involves setting the IP address and subnet mask of each interface, adding routes or enabling a routing protocol, and setting passwords. A home "Wi-Fi router" combines a router, a switch, an access point and a modem.
Gateways and Other Devices
A gateway connects networks that use different protocols or architectures, translating between them; it can work at any layer up to the application layer. The default gateway of a computer is the router that it sends traffic to when the destination is on another network. Other devices include access points (connect wireless devices to a wired LAN), modems (modulate and demodulate signals), firewalls and network interface cards.
Table 1.6: Networking devices by layer
| Device | OSI layer | Forwards using |
|---|---|---|
| Hub, repeater | 1 (physical) | Bits to all ports |
| Bridge, switch | 2 (data link) | MAC addresses |
| Router | 3 (network) | IP addresses |
| Gateway | Up to 7 | Protocol translation |
Example 1.6: Hub and switch
Problem: Eight computers are connected through a 100 Mbps hub, then through a 100 Mbps switch. Each computer sends to a different partner. Compare the bandwidth available to each pair.
Solution:
- A hub forms one collision domain; all eight share 100 Mbps, so only one can send at a time.
- A switch gives each port its own collision domain and forwards only to the destination port.
- With a switch, four pairs can each use 100 Mbps at once (more with full-duplex).
Result: About 12.5 Mbps per computer on the hub against the full 100 Mbps per port on the switch.
mac_table = {}
frames = [("PC-A", "PC-B", 1), ("PC-B", "PC-A", 2),
("PC-C", "PC-A", 3)]
for src, dst, port in frames:
mac_table[src] = port # learn source port
out = mac_table.get(dst)
action = f"forward to port {out}" if out else "flood all ports"
print(f"{src}->{dst}: learned {src}@port{port}, {action}")
print("MAC table:", mac_table)
Output
PC-A->PC-B: learned PC-A@port1, flood all ports
PC-B->PC-A: learned PC-B@port2, forward to port 1
PC-C->PC-A: learned PC-C@port3, forward to port 1
MAC table: {'PC-A': 1, 'PC-B': 2, 'PC-C': 3}
Common mistakes
- Thinking that a hub sends a frame only to its destination. It sends to all ports.
- Saying that a switch connects different networks. A router does.
- Confusing the default gateway (a router) with a protocol gateway.
Key takeaways
- Hubs and repeaters work at layer 1 and broadcast bits.
- Bridges and switches work at layer 2 and forward by MAC address.
- Routers work at layer 3, forward by IP address and connect networks.
- Gateways translate between different protocols.
Practice questions
- At which layer does a switch work?
- What does a router use to forward packets?
- What is a default gateway?
Answers to the practice questions
- The data link layer (layer 2).
- IP addresses and its routing table.
- The router to which a computer sends traffic for other networks.
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit I
