Ethernet LAN Switching (CCNA 200-301)
OSI Model & Encapsulation Review
- Layer 1 (Physical): Defines physical characteristics (voltage, cables, connectors). Converts digital bits to electrical/radio signals.
- Layer 2 (Data Link): Provides node-to-node connectivity. Defines framing, physical addressing (MAC), and error detection.
- Protocol Data Units (PDUs): The stages of encapsulation as data moves down the OSI model.
- Data (L5-L7) $\rightarrow$ Segment (L4) $\rightarrow$ Packet (L3) $\rightarrow$ Frame (L2).
Ethernet Frame Structure
An Ethernet frame encapsulates a Layer 3 Packet with a Layer 2 Header and Trailer.
Header & Trailer Fields
| Field | Size | Purpose |
|---|---|---|
| Preamble | 7 bytes (56 bits) | Alternating 1s and 0s for receiver clock synchronization. |
| Start Frame Delimiter (SFD) | 1 byte (8 bits) | Indicates the end of the preamble and start of the actual frame. |
| Destination MAC | 6 bytes (48 bits) | The physical address of the intended recipient. |
| Source MAC | 6 bytes (48 bits) | The physical address of the sending device. |
| Type / Length | 2 bytes (16 bits) | $\le$ 1500: Indicates payload Length in bytes. $\ge$ 1536: Indicates Type (e.g., 0x0800 = IPv4, 0x86DD = IPv6, 0x0806 = ARP). |
| Payload & Padding | 46 - 1500 bytes | The encapsulated Layer 3 Packet. If payload is < 46 bytes, padding (hex 00) is added. |
| Frame Check Sequence (FCS) | 4 bytes (32 bits) | Used for error detection via Cyclic Redundancy Check (CRC). |
Things to note:
- The Preamble and SFD (8 bytes total) are technically not considered part of the standard 18-byte Ethernet Header+Trailer, making the total frame overhead 26 bytes if included, or 18 bytes if excluded.
- Minimum Frame Size: 64 bytes (excluding Preamble/SFD). Therefore, the minimum payload is 46 bytes. If you send a 36-byte ping, 10 bytes of padding (
0000...) are added.
MAC Addresses
- Definition: A 48-bit (6-byte) physical address assigned to a device at manufacturing. Also called a Burned-In Address (BIA).
- Format: Written in hexadecimal (e.g.,
0C2F.B011.9D00or0C-2F-B0-11-9D-00). - Structure:
- First 3 bytes (24 bits): OUI (Organizationally Unique Identifier). Identifies the manufacturer (e.g., Cisco, Dell).
- Last 3 bytes (24 bits): Unique identifier assigned by the manufacturer to the specific device.
Switch Operations: Learning, Forwarding, and Flooding
Switches operate at Layer 2 and use the MAC Address Table (Content Addressable Memory) to make forwarding decisions.
1. MAC Address Learning
- Concept: Switches learn MAC addresses by inspecting the Source MAC Address of incoming frames.
- Process: When a frame arrives on interface
Gi0/1with Source MACAAAA.AAAA.AAAA, the switch adds an entry mappingAAAA.AAAA.AAAAtoGi0/1. - Aging Timer: Dynamically learned MAC addresses are removed from the table after 5 minutes of inactivity.
2. Frame Forwarding & Flooding
- Concept: Switches forward frames by inspecting the Destination MAC Address.
- Known Unicast: Destination MAC is in the MAC table. The switch forwards the frame only out of the specific mapped interface.
- Unknown Unicast: Destination MAC is not in the MAC table. The switch floods the frame out of all interfaces except the receiving interface.
- Broadcast: Destination MAC is
FFFF.FFFF.FFFF. The switch floods the frame out of all interfaces except the receiving interface.
graph TD
A[Frame Arrives on Interface] --> B{Read Source MAC}
B --> C[Add/Update MAC Address Table]
A --> D{Read Destination MAC}
D --> E{Is Dest MAC FFFF.FFFF.FFFF?}
E -->|Yes| F[Flood out all ports except receiving port]
E -->|No| G{Is Dest MAC in MAC Table?}
G -->|Yes| H[Forward out specific mapped port]
G -->|No| F
Things to note:
- Common Misconception: Switches use the Source MAC to learn, but the Destination MAC to forward.
- Switches do not separate LANs; routers do. Switches expand a single LAN.
Address Resolution Protocol (ARP)
- Concept: Used to discover the Layer 2 (MAC) address of a known Layer 3 (IPv4) address.
- ARP Request: Sent as a Broadcast (Dest MAC:
FFFF.FFFF.FFFF). Message: “Who has [Target IP]? Tell [Sender IP]”. - ARP Reply: Sent as a Unicast directly back to the requester. Message: “[Target IP] is at [Target MAC]”.
- ARP Table: Stores IP-to-MAC mappings. Entries age out over time.
The “First Ping Fails” Phenomenon
When pinging a device for the first time, the first ICMP Echo Request often times out.
- Reason: The sending device must pause to broadcast an ARP Request and wait for the ARP Reply to learn the destination MAC address. The initial ping is dropped during this resolution time. Subsequent pings succeed because the MAC is now cached in the ARP table.
Cisco IOS Verification Commands
To verify and manage Layer 2 switching and ARP operations, use the following commands in Privileged EXEC mode (#).
! View the MAC Address Table
Switch# show mac address-table
! Note: Older IOS versions use 'show mac-address-table'
! Clear ALL dynamic MAC addresses from the table
Switch# clear mac address-table dynamic
! Clear a specific dynamic MAC address
Switch# clear mac address-table dynamic address aaaa.bbbb.cccc
! Clear dynamic MAC addresses learned on a specific interface
Switch# clear mac address-table dynamic interface GigabitEthernet0/1
! View the ARP Table (IP to MAC mappings)
Switch# show arp
Things to note:
- The
show mac address-tableoutput includes four columns: VLAN, MAC Address, Type (Dynamic/Static), and Ports. - On a Windows/Mac/Linux host, the equivalent command to view the local ARP table is
arp -a. - Ping defaults in Cisco IOS: Sends 5 ICMP Echo Requests of 100 bytes each.
Command Summary Reference
| Command | Description |
|---|---|
show mac address-table |
Displays the switch’s MAC address table (VLAN, MAC, Type, Port). |
clear mac address-table dynamic |
Flushes all dynamically learned MAC addresses (forces re-learning). |
clear mac address-table dynamic address <mac> |
Removes a specific MAC address entry. |
clear mac address-table dynamic interface <id> |
Removes all MAC entries associated with a specific interface. |
show arp |
Displays the device’s ARP table (IPv4 to MAC mappings). |
ping <ip> |
Tests reachability using ICMP Echo Requests (Default: 5x 100-byte packets). |