Network Devices
Several kinds of box move data around a network. They differ in how much of a packet they read before deciding what to do with it. That is exactly what the OSI layers in the next lesson describe, so this lesson notes each device's layer.
Overview
| Device | Layer | Looks at | Does |
|---|---|---|---|
| NIC (network interface card) | 1–2 | bits, MAC address | connects a host to a link; has a burned-in MAC address |
| Repeater / hub | 1 | nothing: just bits | regenerates the signal and sends it out of every port |
| Bridge / switch | 2 | destination MAC address | forwards a frame only out of the port where that MAC lives |
| Router | 3 | destination IP address | forwards packets between different networks |
| Access point | 2 | MAC addresses | bridges Wi-Fi clients onto the wired LAN |
| Modem | 1 | signals | converts between digital data and the line's signals (DSL, cable, fibre ONT) |
| Firewall | 3–7 | addresses, ports, sometimes content | allows or blocks traffic by rules |
| Load balancer | 4–7 | ports, HTTP requests | spreads client requests over several servers |
A home "router" is really several devices in one plastic box: a modem, a router, a small switch, a Wi-Fi access point, a firewall, a DHCP server and a DNS forwarder.
Hub versus switch
A hub repeats every incoming bit out of every other port. All hosts share the bandwidth and see each other's traffic, and if two talk at once their signals collide. A switch learns which MAC address lives on which port and sends each frame only where it needs to go. Let's simulate both forwarding a few frames between four PCs:
ports = {"PC-A": 1, "PC-B": 2, "PC-C": 3, "PC-D": 4}
frames = [("PC-A", "PC-C"), ("PC-B", "PC-D"), ("PC-C", "PC-A")]
def hub(src, dst):
return [p for p in ports.values() if p != ports[src]]
def switch(src, dst):
return [ports[dst]] # assumes the switch already knows every port
for name, device in [("hub", hub), ("switch", switch)]:
total = 0
print(name)
for src, dst in frames:
out = device(src, dst)
total += len(out)
print(f" {src} -> {dst}: sent out of ports {out}")
print(f" copies transmitted: {total}")hub
PC-A -> PC-C: sent out of ports [2, 3, 4]
PC-B -> PC-D: sent out of ports [1, 3, 4]
PC-C -> PC-A: sent out of ports [1, 2, 4]
copies transmitted: 9
switch
PC-A -> PC-C: sent out of ports [3]
PC-B -> PC-D: sent out of ports [4]
PC-C -> PC-A: sent out of ports [1]
copies transmitted: 3
The hub sends three copies of every frame; the switch sends one. With 48 ports the difference is enormous, and the switch also lets PC-A and PC-B transmit at the same time without collisions. Hubs are obsolete today.
Switch versus router
A switch connects devices within one network. A router connects different networks and picks the next hop toward the destination's network. A simple way to tell what a host must do is to check whether the destination is on its own subnet:
import ipaddress
my_network = ipaddress.ip_network("192.168.1.0/24")
gateway = "192.168.1.1"
for dest in ["192.168.1.42", "192.168.1.200", "10.0.0.5", "93.184.215.14"]:
if ipaddress.ip_address(dest) in my_network:
print(f"{dest:<15} same network -> deliver directly through the switch")
else:
print(f"{dest:<15} other network -> send to the router {gateway}")192.168.1.42 same network -> deliver directly through the switch
192.168.1.200 same network -> deliver directly through the switch
10.0.0.5 other network -> send to the router 192.168.1.1
93.184.215.14 other network -> send to the router 192.168.1.1
You will learn exactly how this decision works (subnet masks, ARP, default gateways) in the network layer section.
Collision and broadcast domains
Two classic terms describe how devices divide a network:
- A collision domain is the set of devices whose transmissions can collide. A hub puts all its ports in one collision domain; each switch port is its own collision domain (and with full duplex, collisions disappear entirely).
- A broadcast domain is the set of devices that receive each other's broadcasts (frames sent to
ff:ff:ff:ff:ff:ff). A switch forwards broadcasts out of all ports, so it is one broadcast domain. A router does not forward broadcasts, so each router interface starts a new broadcast domain. VLANs also split broadcast domains.
# A router with three interfaces; switches and hubs hang off each one.
segments = {
"router port 1": {"device": "switch", "ports_used": 12},
"router port 2": {"device": "hub", "ports_used": 5},
"router port 3": {"device": "switch", "ports_used": 8},
}
collision_domains = 0
for name, seg in segments.items():
cds = seg["ports_used"] if seg["device"] == "switch" else 1
collision_domains += cds
print(f"{name}: {seg['device']:<6} -> {cds} collision domain(s)")
print("broadcast domains:", len(segments))
print("collision domains:", collision_domains)router port 1: switch -> 12 collision domain(s)
router port 2: hub -> 1 collision domain(s)
router port 3: switch -> 8 collision domain(s)
broadcast domains: 3
collision domains: 21
Tip: Remember the rule of thumb: switches break up collision domains, routers break up broadcast domains.
Layer 3 switches and other hybrids
The lines blur in practice. A layer 3 switch routes between VLANs in hardware at switch speed. Next-generation firewalls inspect application data. Cloud networks replace many boxes with software ("virtual switches" and "virtual routers"). The layer model still tells you what each function does, even when one device performs several of them.
Test yourself
Which device forwards traffic based on destination IP addresses?
- Hub
- Switch
- Router
- Repeater
A frame arrives at a hub with 8 ports in use. How many ports send it out?
- 1
- 7
- 8
- None, hubs drop frames
Which device breaks up broadcast domains?
- Hub
- Switch (without VLANs)
- Router
- Repeater