Switch
Table of Contents
A Layer 2 network device that connects multiple devices within a LAN and forwards frames based on MAC addresses. Unlike a hub which broadcasts to all ports, a switch learns which device is on which port and sends frames only to the intended destination. Managed switches add VLAN support, port security, STP, and QoS configuration.
Related: MAC Address VLANs Spanning Tree Protocol Router Hub Ethernet
Switch Types
| Type | Layer | Capability |
|---|---|---|
| Unmanaged | L2 | Plug-and-play, no configuration, basic MAC forwarding |
| Managed | L2 | VLANs, STP, port security, SNMP, CLI/web config |
| Layer 3 (multilayer) | L2+L3 | Routing between VLANs, acts as router for inter-VLAN traffic |
| PoE switch | L2 or L3 | Delivers power over Ethernet to phones, APs, cameras |
How It Works
MAC Address Table (CAM Table)
The switch builds a table mapping MAC addresses to ports by inspecting the source MAC of incoming frames:
Port 1 → AA:BB:CC:DD:EE:01 (learned from device on port 1) Port 2 → AA:BB:CC:DD:EE:02 Port 3 → AA:BB:CC:DD:EE:03
When a frame arrives destined for a known MAC, it is forwarded only to that port. If the destination MAC is unknown, the frame is flooded to all ports until a response is received and the table is updated.
Broadcast Domain
By default all ports on a switch share one broadcast domain — a broadcast frame is forwarded to all ports. VLANs segment the switch into multiple broadcast domains.
Common Cisco CLI Commands
# Show MAC address table show mac address-table # Show all interfaces and their status show interfaces status # Show VLAN assignments show vlan brief # Show spanning tree state show spanning-tree # Assign port to VLAN (access port — single VLAN, for end devices) interface FastEthernet 0/1 switchport mode access switchport access vlan 10 # Configure trunk port (carries multiple VLANs — for uplinks) interface GigabitEthernet 0/1 switchport mode trunk switchport trunk allowed vlan 10,20,30 # Port security — limit MAC addresses per port interface FastEthernet 0/1 switchport port-security maximum 2 switchport port-security violation restrict switchport port-security mac-address sticky # Enable portfast (skip STP listening/learning on access ports) interface FastEthernet 0/1 spanning-tree portfast
Security Relevance
MAC Flooding
An attacker floods the switch with frames containing random source MAC addresses, filling the CAM table. When full, the switch degrades to hub behaviour — flooding all frames to all ports, enabling sniffing.
# macof (dsniff package) — MAC flood attack macof -i eth0
Mitigation: port security limiting MACs per port.
VLAN Hopping
Without proper trunk configuration an attacker on an access port may be able to send frames tagged with a different VLAN ID, gaining access to traffic on that VLAN. Mitigated by:
- Setting unused ports to a dedicated unused VLAN
- Disabling DTP (Dynamic Trunking Protocol) on access ports
- Never using VLAN 1 for user traffic
DHCP Starvation / Spoofing
An attacker exhausts the DHCP pool with requests then serves a rogue DHCP server. Mitigated by DHCP snooping — a managed switch feature that only allows DHCP responses from trusted ports.
Tips
- If you get a cheap managed switch from work, VLAN configuration is the most immediately useful feature — isolate lab traffic from your home network without needing a separate physical network
- Trunk ports carry all VLANs by default — explicitly whitelist only the VLANs needed on each trunk
- Portfast should only be enabled on access ports connected to end devices, not uplinks — applying it to trunk ports can cause STP loops
- SNMP on unmanaged/default-config switches is a frequent
misconfiguration finding — community string
publicallows read access to switch configuration