Layer 2 Switching
Layer 2 Switching
· Jomplair · Lexicon Lab

Layer 2 Switching: A Technical Deep Dive


Layer 2 switching operates at the Data Link Layer (Layer 2) of the OSI model, focusing on MAC addresses to forward Ethernet frames within a local area network (LAN). Unlike routers, which use IP addresses (Layer 3), Layer 2 switches build and maintain a MAC address table (CAM table) to efficiently direct traffic between devices on the same network segment. Below is a detailed breakdown of its mechanisms, protocols, and use cases:

  1. Core Functions of Layer 2 Switching
  1. MAC Address Learning:
    • Switches dynamically learn MAC addresses by inspecting the source MAC of incoming frames and mapping them to the corresponding switch port.
    • Example: When device A sends a frame to device B, the switch records A's MAC address and its ingress port in the CAM table.
  2. Frame Forwarding:
    • Unicast: If the destination MAC is in the CAM table, the frame is forwarded only to the relevant port.
    • Broadcast/Multicast: Frames are flooded to all ports except the ingress port (unless IGMP snooping is enabled).
    • Unknown Unicast: Frames with unlearned MAC addresses are flooded to all ports.
  3. Loop Prevention:
    • Uses protocols like Spanning Tree Protocol (STP) to block redundant paths and prevent broadcast storms.
  1. Key Components & Technologies
  2. MAC Address Table (CAM Table)
  • Stores mappings of MAC addresses ↔ Switch Ports.
  • Entries age out after a configurable time (default: 300 seconds).
  • Example Table:

MAC Address

Port

VLAN

00:1A:2B:3C:4D:5E

Gi0/1

10

AA:BB:CC:DD:EE:FF

Gi0/2

20

  1. VLANs (Virtual LANs)
  • Logically partitions a physical switch into multiple isolated broadcast domains.
  • Traffic between VLANs requires Layer 3 routing.
  1. Link Aggregation (EtherChannel/LACP)
  • Combines multiple physical links into a single logical link for redundancy and increased bandwidth.
  • Uses protocols like LACP (802.3ad) to negotiate member ports.
  1. Security Features
  • Port Security: Restricts MAC addresses allowed on a port.
  • DHCP Snooping: Blocks rogue DHCP servers.
  • Dynamic ARP Inspection (DAI): Prevents ARP spoofing.
  1. Layer 2 vs. Layer 3 Switching

Feature

Layer 2 Switching

Layer 3 Switching

Forwarding Basis

MAC addresses

IP addresses

Broadcast Domains

Single domain (unless using VLANs)

Multiple domains (routed networks)

Protocols

STP, VLANs, LACP

IP, OSPF, ACLs

Use Case

LAN segmentation, intra-VLAN traffic

Inter-VLAN routing, WAN connectivity

  1. Key Protocols in Layer 2 Switching
  1. Spanning Tree Protocol (STP):
    • Prevents loops by blocking redundant paths.
    • Variants: RSTP (802.1w)MSTP (802.1s).
  2. LLDP (802.1AB):
    • Discovers neighboring devices (e.g., switches, routers).
  3. VTP (VLAN Trunking Protocol):
    • Synchronizes VLAN configurations across switches (largely deprecated in favor of manual configs).
  1. Benefits of Layer 2 Switching
  • Low Latency: Hardware-based forwarding (ASICs) ensures near-wire-speed performance.
  • Scalability: Supports large networks via VLANs and link aggregation.
  • Cost-Effective: Simpler and cheaper than Layer 3 switches for intra-LAN traffic.
  1. Limitations
  • Broadcast Storms: Requires STP to mitigate risks in redundant topologies.
  • Limited Segmentation: VLANs provide isolation but require Layer 3 for inter-VLAN routing.
  • No Routing: Cannot forward traffic between IP subnets without a Layer 3 device.
  1. Use Cases
  1. Enterprise LANs: Connect end-user devices (PCs, printers) within the same subnet.
  2. Data Centers: Build high-speed, low-latency server-to-server networks.
  3. VoIP/Video Conferencing: Prioritize real-time traffic using QoS on VLANs.
  4. Industrial Networks: Deploy deterministic, loop-free topologies with RSTP.
  1. Workflow Example: Frame Forwarding
  1. Frame Arrival: A frame from MAC A enters port Gi0/1.
  2. MAC Learning: Switch adds A → Gi0/1 to the CAM table.
  3. Destination Lookup:
    • If MAC B is in the CAM table, forward to the mapped port.
    • If MAC B is unknown, flood to all ports in the same VLAN.
  4. Loop Prevention: STP blocks alternate paths to avoid loops.

 

Latest posts