Network Switch – MAC Learning, VLANs, STP, Port Security & Inter-VLAN Routing
1. What Is a Network Switch?
A network switch is an intelligent Layer 2 (and optionally Layer 3) device that interconnects devices within a LAN (Local Area Network). Unlike a hub — which blindly copies every incoming frame out every port, creating collisions — a switch learns which device is connected to each port and forwards frames only to the correct destination port.
Hub (Layer 1) — collision domain spans ALL ports: PC-A sends frame to PC-B. Hub copies frame to PC-B, PC-C, PC-D, and Server simultaneously. If PC-C sends at the same time as PC-A: COLLISION -- both frames destroyed. All devices share one collision domain and one broadcast domain. Switch (Layer 2) — separate collision domain per port: PC-A sends frame to PC-B. Switch checks CAM table: PC-B is on Gi0/2. Switch sends frame ONLY out Gi0/2. PC-C and PC-D see nothing. PC-C can transmit simultaneously -- no collision (full-duplex per port). All ports = separate collision domains. One broadcast domain per VLAN.
Related pages: CAM Table | MAC Addresses | Access & Trunk Ports | VLANs | Trunking (802.1Q) | Root Bridge Election (STP) | Spanning Tree | show mac address-table | show vlan | show interfaces | EtherChannel | Routers | VLAN Configuration Lab | Inter-VLAN Routing Lab | Layer 2 Troubleshooting Lab
2. Switch vs Hub vs Router — OSI Layer Comparison
| Device | OSI Layer | Forwarding Basis | Collision Domain | Broadcast Domain | Intelligence |
|---|---|---|---|---|---|
| Hub | Layer 1 (Physical) | None — floods every port | One (all ports) | None — pure signal repeater | |
| Switch (L2) | Layer 2 (Data Link) | MAC addresses (CAM table) | One per port (full-duplex) | One per VLAN | Learns MAC-to-port mappings; forwards or floods |
| Switch (L3) | Layers 2 and 3 | MAC addresses AND IP addresses | One per port | One per VLAN; routes between VLANs | Full L2 switching + hardware-based IP routing. See Layer 3 Switch Routing. |
| Router | Layer 3 (Network) | IP addresses (routing table) | One per interface | One per interface (breaks broadcast domains) | Routing table; inter-network forwarding; NAT, ACLs |
3. Types of Switches
| Type | Description | Configurable? | Typical Use Case |
|---|---|---|---|
| Unmanaged | Plug-and-play; no configuration interface. Fixed functionality. | No | Small offices, home networks, simple device connectivity where VLANs and security are not needed |
| Managed | Full CLI/GUI/SNMP access. Supports VLANs, STP, QoS, port security, SNMP monitoring, ACLs. | Yes | Enterprise networks requiring segmentation, security, redundancy, and monitoring |
| Smart / Partially Managed | Web GUI only; limited feature set compared to fully managed. Typically supports basic VLANs and QoS. | Limited | Small-medium businesses needing basic VLAN support without enterprise complexity |
| Layer 2 (L2) | Forwards frames based on MAC addresses only. No IP routing. | Yes (managed) | Access layer — connecting end devices (PCs, phones, printers) to the network |
| Layer 3 (L3) | Performs both MAC-based switching AND IP-based routing (inter-VLAN routing) in hardware ASIC. Much faster than router-on-a-stick. | Yes | Distribution and core layers; inter-VLAN routing without a separate router (Cisco Catalyst 3850, 9300) |
| Stackable | Multiple physical chassis interconnected via a high-speed stacking bus and managed as a single logical device. Add/remove stack members without downtime. | Yes | Enterprise access layer needing scalability — add switches as port count grows; one management IP for entire stack |
| Modular / Chassis | Chassis-based with field-replaceable line cards (port modules), supervisor engines, and power supplies. Highly resilient. | Yes | Core and data centre — large port density, redundant supervisors (Cisco Catalyst 6500, 9400) |
| PoE Switch | Delivers 802.3af/at/bt power over Ethernet to connected devices alongside data. | Yes | Powering IP phones, wireless APs, IP cameras, and other PoE devices without separate power supplies |
4. MAC Address Learning and Frame Forwarding
The switch's entire intelligence rests on its CAM table (Content Addressable Memory table, also called the MAC address table). Every frame received triggers two actions: learn the source MAC and look up the destination MAC.
Frame forwarding decision logic:
Frame arrives on Gi0/1. Source MAC = 0011.AAAA.AAAA, Dest MAC = 0022.BBBB.BBBB
Step 1 -- LEARN SOURCE MAC:
Record: 0011.AAAA.AAAA is reachable via Gi0/1
(Resets aging timer to 300 sec for this entry)
Step 2 -- LOOK UP DESTINATION MAC:
Case A: Destination MAC in CAM table:
0022.BBBB.BBBB -> Gi0/3
Forward frame out Gi0/3 ONLY (unicast forwarding)
Case B: Destination MAC NOT in CAM table (unknown unicast):
Flood frame out ALL ports in same VLAN except ingress Gi0/1
(PC-B's reply will populate its entry)
Case C: Destination is broadcast (FF:FF:FF:FF:FF:FF):
Flood frame out ALL ports in same VLAN except ingress
(ARP requests, DHCP Discover use broadcast)
Case D: Destination is multicast:
Flood to all ports in VLAN (unless IGMP Snooping active)
With IGMP Snooping: send only to ports with interested receivers
See CAM Table and show mac address-table
for full MAC learning and CAM table details.
Frame Switching Methods
| Method | How It Works | Latency | Error Checking | When Used |
|---|---|---|---|---|
| Store-and-Forward | Receives entire frame into buffer, checks FCS (CRC) for errors, THEN forwards | Higher (entire frame must arrive first) | Full — corrupted frames are dropped before forwarding | Default on most modern Cisco switches; required for QoS classification and different-speed port connections |
| Cut-Through | Forwards immediately after reading destination MAC (first 6 bytes of frame header) | Lower — starts forwarding in ~14 bytes | None — corrupted frames can propagate | Low-latency environments (HFT, storage networks); when all ports same speed |
| Fragment-Free | Reads first 64 bytes (minimum Ethernet frame) before forwarding; catches collision fragments | Moderate | Partial — catches runts (collision fragments under 64B) | Compromise between store-and-forward and cut-through; reduces collision fragment propagation |
5. VLANs — Virtual LANs
VLANs logically partition a single physical switch into multiple independent broadcast domains. Devices in different VLANs cannot communicate at Layer 2 even if physically connected to the same switch — a router or Layer 3 switch is required for inter-VLAN communication.
Without VLANs (one switch, all devices same broadcast domain): Finance-PC, HR-PC, IT-PC, Server all share one broadcast domain. Finance ARP request floods to HR-PC, IT-PC, and Server -- inefficient and a security concern (HR can see Finance traffic). With VLANs (logical segmentation): VLAN 10 (Finance): Finance-PC-1, Finance-PC-2 VLAN 20 (HR): HR-PC-1, HR-PC-2 VLAN 30 (IT): IT-PC-1, IT-Server Finance ARP request floods ONLY to Finance-PC-1 and Finance-PC-2. HR-PC never sees Finance broadcasts. To route between Finance and HR: must go through a router or L3 switch.
VLAN Configuration — Cisco IOS
! ── Create VLANs ────────────────────────────────────────────────────────── Switch(config)# vlan 10 Switch(config-vlan)# name Finance Switch(config-vlan)# exit Switch(config)# vlan 20 Switch(config-vlan)# name HR Switch(config-vlan)# exit ! ── Assign access port to VLAN ──────────────────────────────────────────── Switch(config)# interface GigabitEthernet0/1 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 10 Switch(config-if)# spanning-tree portfast ! For end-device ports Switch(config-if)# spanning-tree bpduguard enable ! ── Configure trunk port (between switches) ─────────────────────────────── Switch(config)# interface GigabitEthernet0/24 Switch(config-if)# switchport mode trunk Switch(config-if)# switchport trunk encapsulation dot1q ! Older IOS Switch(config-if)# switchport trunk allowed vlan 10,20,30 Switch(config-if)# switchport trunk native vlan 99 ! Change from default VLAN 1 ! ── Verify ──────────────────────────────────────────────────────────────── Switch# show vlan brief VLAN Name Status Ports ---- ---------------------- --------- ---------------------------------- 1 default active Gi0/2, Gi0/3, Gi0/4 10 Finance active Gi0/1 20 HR active Gi0/5, Gi0/6 30 IT active Gi0/7, Gi0/8 1002 fddi-default act/unsup ... Switch# show interfaces trunk Port Mode Encap Status Native vlan Gi0/24 on 802.1q trunking 99 Port Vlans allowed on trunk Gi0/24 10,20,30 Port Vlans allowed and active in management domain Gi0/24 10,20,30
See show vlan for detailed output annotation,
Access & Trunk Ports for the full port configuration reference,
and VLANs for the conceptual overview.
Hands-on practice: VLAN Configuration Lab |
Assigning VLANs to Switch Ports Lab.
802.1Q VLAN Tagging
802.1Q adds a 4-byte tag to the Ethernet frame header:
Normal Ethernet frame:
| Dest MAC (6B) | Src MAC (6B) | EtherType (2B) | Data | FCS |
802.1Q tagged frame:
| Dest MAC (6B) | Src MAC (6B) | 802.1Q Tag (4B) | EtherType (2B) | Data | FCS |
^^^^^^^^^^^^^^^^^
| TPID (2B) = 0x8100 | PCP (3b) | DEI (1b) | VLAN ID (12b) |
TPID 0x8100 = identifies this as an 802.1Q frame
PCP (Priority Code Point) = 3 bits for QoS (0-7)
VLAN ID (VID) = 12 bits = VLAN 0-4095 (0 and 4095 reserved; usable 1-4094)
Native VLAN: frames on the native VLAN are NOT tagged on trunk ports.
Mismatch of native VLAN on each end = VLAN hopping vulnerability!
Best practice: set native VLAN to an unused VLAN (e.g., 99).
See Trunking (802.1Q) for full 802.1Q trunk configuration detail.
6. Inter-VLAN Routing — Layer 3 Switch vs Router-on-a-Stick
Devices in different VLANs cannot communicate at Layer 2. To route between VLANs, two approaches exist: router-on-a-stick (single router interface with sub-interfaces) or a Layer 3 switch with SVIs (Switched Virtual Interfaces).
Method 1: Router-on-a-Stick
Topology: Switch --trunk--> Router Gi0/0 Router Gi0/0 has sub-interfaces for each VLAN. ! Switch side -- configure trunk to router: Switch(config)# interface Gi0/24 Switch(config-if)# switchport mode trunk ! Router side -- sub-interfaces: Router(config)# interface GigabitEthernet0/0.10 Router(config-subif)# encapsulation dot1Q 10 Router(config-subif)# ip address 192.168.10.1 255.255.255.0 Router(config)# interface GigabitEthernet0/0.20 Router(config-subif)# encapsulation dot1Q 20 Router(config-subif)# ip address 192.168.20.1 255.255.255.0 Router(config)# interface GigabitEthernet0/0.30 Router(config-subif)# encapsulation dot1Q 30 Router(config-subif)# ip address 192.168.30.1 255.255.255.0 Router(config)# interface GigabitEthernet0/0 Router(config-if)# no shutdown ! Bring up parent interface ! Default gateways: VLAN 10 hosts use 192.168.10.1, etc. ! Limitation: all inter-VLAN traffic passes through router -- single link bottleneck
Method 2: Layer 3 Switch with SVIs (Preferred)
! Enable IP routing on L3 switch: L3Switch(config)# ip routing ! Create SVIs (one per VLAN -- acts as default gateway): L3Switch(config)# interface vlan 10 L3Switch(config-if)# ip address 192.168.10.1 255.255.255.0 L3Switch(config-if)# no shutdown L3Switch(config-if)# description Gateway-for-VLAN10 L3Switch(config)# interface vlan 20 L3Switch(config-if)# ip address 192.168.20.1 255.255.255.0 L3Switch(config-if)# no shutdown ! Traffic between VLAN 10 and VLAN 20 routes in hardware ASIC -- ! no external router needed, wire-speed performance. ! Verify SVIs: L3Switch# show interfaces vlan 10 Vlan10 is up, line protocol is up Internet address is 192.168.10.1/24 L3Switch# show ip route C 192.168.10.0/24 is directly connected, Vlan10 C 192.168.20.0/24 is directly connected, Vlan20
See Inter-VLAN Routing Lab for hands-on practice with both methods.
7. Spanning Tree Protocol (STP)
STP (IEEE 802.1D) prevents Layer 2 loops in networks with redundant switch links. Without STP, a broadcast frame would loop indefinitely between switches, consuming all bandwidth within seconds.
Triangle topology without STP: SW1 -- SW2 -- SW3 -- SW1 PC-A sends broadcast -> SW1 forwards to SW2 and SW3 SW2 forwards to SW3 (arrives again at SW3), SW3 forwards back to SW1... Frames multiply exponentially -- BROADCAST STORM -- network fails. STP solution: 1. Elect a ROOT BRIDGE (lowest Bridge ID) 2. Calculate shortest path to root from each switch 3. Block redundant ports (Alternate/Blocking state) 4. Only Root Ports and Designated Ports forward traffic Result: Loop-free tree with blocked port as standby backup.
! Verify STP root and port roles:
Switch# show spanning-tree vlan 10
VLAN0010
Root ID Priority 4097
Address 0011.1111.1111
This bridge is the root
...
Interface Role Sts Cost Prio.Nbr Type
Gi0/1 Desg FWD 4 128.1 P2p
Gi0/2 Desg FWD 4 128.2 P2p
Gi0/3 Altn BLK 4 128.3 P2p <-- blocked to prevent loop
! Configure root bridge (recommended over relying on MAC tiebreaker):
Switch(config)# spanning-tree vlan 10 root primary
Switch(config)# spanning-tree vlan 20 root secondary
See Root Bridge Election, STP Port Roles, Spanning Tree Protocol, and PVST+ for detailed STP coverage. PortFast & BPDU Guard should be configured on all access ports.
8. Switch Port Types and Configuration
| Port Type | Description | Configuration | Use Case |
|---|---|---|---|
| Access Port | Carries traffic for exactly one VLAN. Frames are NOT tagged (untagged). Connected device is unaware of VLANs. | switchport mode accessswitchport access vlan [id] |
PC, printer, IP phone, server connected to a specific VLAN |
| Trunk Port | Carries traffic for multiple VLANs. Frames are 802.1Q tagged with VLAN ID (except native VLAN frames). | switchport mode trunkswitchport trunk allowed vlan [list] |
Switch-to-switch links, switch-to-router (router-on-a-stick), switch-to-AP (multiple SSIDs as VLANs) |
| Routed Port (L3) | Behaves like a router interface on an L3 switch. Has an IP address; does not do Layer 2 switching. | no switchportip address [addr] [mask] |
Uplink from distribution L3 switch to core router or firewall |
| SVI (Switched Virtual Interface) | Virtual interface for a VLAN on an L3 switch. Acts as the default gateway for that VLAN. | interface vlan [id]ip address [addr] [mask] |
Inter-VLAN routing gateway; VLAN management access |
See Access & Trunk Ports for the complete port configuration guide.
9. Port Security
Port security restricts which MAC addresses can communicate through a switch port. It limits the maximum number of MACs and can lock a port to specific known MACs — preventing rogue device connections.
! Configure port security on an access port: Switch(config)# interface GigabitEthernet0/5 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 10 Switch(config-if)# switchport port-security ! Enable port security Switch(config-if)# switchport port-security maximum 1 ! Allow only 1 MAC Switch(config-if)# switchport port-security violation shutdown ! Err-disable on violation Switch(config-if)# switchport port-security mac-address sticky ! Auto-learn & lock MAC ! Violation modes: ! shutdown -- err-disables port (default); manual recovery needed ! restrict -- drops violating frames + syslog; port stays UP ! protect -- drops violating frames silently; NO syslog ! Verify port security: Switch# show port-security interface GigabitEthernet0/5 Port Security : Enabled Port Status : Secure-up Violation Mode : Shutdown Maximum MAC Addresses : 1 Sticky MAC Addresses : 1 Security Violation Count : 0 ! Recover an err-disabled port: Switch(config)# interface GigabitEthernet0/5 Switch(config-if)# shutdown Switch(config-if)# no shutdown
See Port Security Overview, Sticky MAC, Violation Modes, and Port Security & Sticky MAC Lab.
10. Layer 2 Security Features
| Feature | What It Prevents | How It Works | Key Command |
|---|---|---|---|
| Port Security | Rogue device connections; MAC flooding attacks | Limits MACs per port; violation triggers action (shutdown/restrict/protect) | switchport port-security |
| DHCP Snooping | Rogue DHCP servers assigning incorrect IP addresses to clients (starvation, spoofing) | Marks ports as trusted (uplinks, real DHCP servers) or untrusted (end-device ports). DHCP Offer/Ack only allowed from trusted ports. Builds binding table (MAC-IP-port-VLAN) | ip dhcp snoopingip dhcp snooping vlan [id] |
| Dynamic ARP Inspection (DAI) | ARP spoofing / ARP poisoning attacks (man-in-the-middle) | Validates ARP packets against the DHCP snooping binding table. Discards ARP with MAC-IP bindings not in the table. Requires DHCP Snooping to be configured first. | ip arp inspection vlan [id] |
| 802.1X Port Authentication | Unauthenticated device access to the network | Port blocked until device authenticates via RADIUS (EAP). Authentication before any Layer 2 frames pass. See AAA Authentication Methods. | dot1x system-auth-control |
| PortFast + BPDU Guard | Rogue switch connecting to access port; accidental STP topology changes from end-device ports | PortFast skips STP listening/learning on access ports. BPDU Guard err-disables port if any BPDU received. | spanning-tree portfastspanning-tree bpduguard enable |
| Storm Control | Broadcast/multicast/unicast storms degrading network | Monitors traffic rate per port; shuts down or drops when threshold exceeded (% bandwidth or pps) | storm-control broadcast level [%] |
DHCP Snooping and DAI Configuration
! ── DHCP Snooping ───────────────────────────────────────────────────────── Switch(config)# ip dhcp snooping Switch(config)# ip dhcp snooping vlan 10,20,30 ! Mark uplink/server ports as trusted: Switch(config)# interface GigabitEthernet0/24 Switch(config-if)# ip dhcp snooping trust ! All other (access) ports are untrusted by default. ! Verify: Switch# show ip dhcp snooping DHCP snooping is configured on the following VLANs: 10,20,30 Interface Trusted Rate limit (pps) Gi0/24 yes unlimited Gi0/1 no 15 Switch# show ip dhcp snooping binding MacAddress IpAddress Lease Type VLAN Interface 00:11:AA:BB:CC:01 192.168.10.50 86400 dhcp-sn 10 Gi0/1 ! ── Dynamic ARP Inspection ──────────────────────────────────────────────── Switch(config)# ip arp inspection vlan 10,20,30 ! Uplink ports must also be trusted for ARP inspection: Switch(config)# interface GigabitEthernet0/24 Switch(config-if)# ip arp inspection trust
See DHCP Snooping, Dynamic ARP Inspection, and DHCP Snooping & DAI Lab.
11. EtherChannel (Link Aggregation)
EtherChannel bundles multiple physical links between two switches into one logical link, providing higher bandwidth and redundancy. If one physical link fails, traffic continues on the remaining links with no STP reconvergence.
Without EtherChannel (two links between switches):
SW1 Gi0/1 --- Gi0/1 SW2 (STP blocks one link -- only 1G effective)
SW1 Gi0/2 --- Gi0/2 SW2 (blocked by STP)
With EtherChannel (two links bundled):
SW1 Gi0/1 ---| |--- Gi0/1 SW2
SW1 Gi0/2 ---| Port-Ch |--- Gi0/2 SW2 2G effective bandwidth
| (Po1) | both links active, load-balanced
! Configure LACP EtherChannel (recommended -- IEEE standard):
Switch(config)# interface range GigabitEthernet0/1 - 2
Switch(config-if-range)# channel-group 1 mode active ! LACP active
Switch(config-if-range)# channel-protocol lacp
! Configure the Port-Channel interface:
Switch(config)# interface Port-channel1
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10,20,30
! Alternative: PAgP (Cisco proprietary):
Switch(config-if-range)# channel-group 1 mode desirable ! PAgP
! Verify:
Switch# show etherchannel summary
Flags: D - down P - bundled in port-channel
U - in use S - Layer2
Group Port-channel Protocol Ports
------+-------------+-----------+-------------------------------------------
1 Po1(SU) LACP Gi0/1(P) Gi0/2(P)
See EtherChannel Load Balancing for hashing algorithms and load distribution details.
12. Switch Management
! ── Management VLAN and IP address ─────────────────────────────────────── Switch(config)# vlan 99 Switch(config-vlan)# name Management Switch(config)# interface vlan 99 Switch(config-if)# ip address 10.0.0.10 255.255.255.0 Switch(config-if)# no shutdown Switch(config)# ip default-gateway 10.0.0.1 ! ── SSH access (secure -- replace Telnet) ────────────────────────────── Switch(config)# hostname SW-Core-01 Switch(config)# ip domain-name netstuts.com Switch(config)# crypto key generate rsa modulus 2048 Switch(config)# ip ssh version 2 Switch(config)# line vty 0 15 Switch(config-line)# transport input ssh Switch(config-line)# login local Switch(config)# username admin privilege 15 secret AdminP@ss ! ── Disable Telnet on VTY ───────────────────────────────────────────── Switch(config)# line vty 0 15 Switch(config-line)# transport input ssh ! SSH only; reject Telnet ! ── Enable SNMP for monitoring ──────────────────────────────────────── Switch(config)# snmp-server community PUBLIC ro Switch(config)# snmp-server community PRIVATE rw Switch(config)# snmp-server host 10.0.0.100 version 2c PUBLIC ! ── Console password ────────────────────────────────────────────────── Switch(config)# line console 0 Switch(config-line)# password ConsoleP@ss Switch(config-line)# login Switch(config-line)# exec-timeout 5 0 ! Auto-logout after 5 minutes
See SSH Configuration for the full SSH setup guide,
SNMP for monitoring configuration,
and show running-config to verify the management configuration.
13. Switch Troubleshooting — Commands and Scenarios
| Symptom | Likely Cause | Diagnostic Command | Fix |
|---|---|---|---|
| PC cannot ping gateway (same VLAN) | Port not in correct VLAN; port in wrong mode (trunk instead of access) | show interfaces Gi0/x switchportshow vlan brief |
Verify switchport access vlan [id];
confirm switchport mode access |
| VLANs not passing between switches | Trunk not configured; VLAN not in allowed list; native VLAN mismatch | show interfaces trunk |
Verify trunk mode on both ends; check allowed VLAN list; align native VLAN on both switches. See Layer 2 Troubleshooting Lab. |
| Broadcast storm / MAC flapping | Layer 2 loop — STP not blocking redundant port; unmanaged switch connected without STP | show spanning-treeshow logging | include MACFLAP |
Verify STP running; check all ports for unexpected FWD state; enable STP on any unmanaged connections |
| Port in err-disabled state | Port security violation; BPDU Guard triggered; Loop detected by loop-guard | show interfaces status err-disabledshow port-security interface Gi0/x |
Investigate cause; remove offending device;
shutdown then no shutdown;
or configure errdisable auto-recovery |
| DHCP not working on a VLAN | No DHCP server for VLAN; DHCP Snooping blocking; missing ip helper-address on L3 SVI | show ip dhcp snoopingshow ip dhcp binding |
Check DHCP snooping trust on uplinks; add
ip helper-address on VLAN SVI if DHCP
server is on a different subnet |
Essential Troubleshooting Commands
Switch# show mac address-table ! CAM table entries and ports Switch# show interfaces status ! All ports: speed, duplex, VLAN, status Switch# show interfaces GigabitEthernet0/1 ! Detailed counters: errors, CRC, drops Switch# show vlan brief ! VLAN IDs, names, assigned ports Switch# show interfaces trunk ! Trunk ports, allowed VLANs, native VLAN Switch# show interfaces GigabitEthernet0/1 switchport ! Port mode, VLAN assignment Switch# show spanning-tree vlan 10 ! STP roles and states per VLAN Switch# show port-security interface Gi0/1 ! Port security config and violations Switch# show ip dhcp snooping binding ! DHCP snooping binding table Switch# show ip arp inspection vlan 10 ! DAI statistics Switch# show etherchannel summary ! EtherChannel port-channel status Switch# show version ! IOS version, platform, uptime
See show interfaces,
show vlan,
show mac address-table, and
ping for detailed command references.
For complex layer 2 issues see
Layer 2 Troubleshooting Lab.
14. Key Points & Exam Tips
- Switches operate at Layer 2 (MAC addresses). Layer 3 switches also perform IP routing. Hubs are Layer 1 (no intelligence). Routers are Layer 3 (IP addresses).
- MAC learning: Switch records source MAC + ingress port on every frame. Destination lookup: found = unicast forward; not found = flood (unknown unicast). Aging default = 300 seconds. See CAM Table.
- Store-and-forward = full error checking, higher latency. Cut-through = lowest latency, no error checking. Default on modern Cisco switches = store-and-forward.
- Access port = one VLAN, untagged frames, end devices. Trunk port = multiple VLANs, 802.1Q tagged, between switches or to routers/APs.
- Native VLAN on trunk ports sends frames untagged. Both sides must match or VLAN hopping is possible. Best practice: change from VLAN 1 to unused VLAN.
- Inter-VLAN routing: router-on-a-stick (router with
sub-interfaces, single trunk) or L3 switch with SVIs and
ip routing(faster, no external router needed). - STP prevents Layer 2 loops. Root Bridge = lowest BID. Root Port = best path to root. Designated Port = best for a segment. Blocked ports prevent loops. All root bridge ports = Designated. See Root Bridge Election.
- Port security violation modes: shutdown (err-disables, logs), restrict (drops + logs, port UP), protect (drops silently, no log).
- DHCP Snooping prevents rogue DHCP servers. Trusted ports (uplinks/servers) vs untrusted (access). Builds binding table used by DAI. DAI prevents ARP spoofing.
- EtherChannel bundles links for bandwidth + redundancy. LACP
(IEEE,
mode active/passive) or PAgP (Cisco,mode desirable/auto). STP treats bundle as one port. - Management: use SSH (not Telnet) on VTY lines;
configure a management VLAN SVI; monitor with SNMP.
Verify with
show running-config.
Related pages: CAM Table | Access & Trunk Ports | Root Bridge Election | STP Port Roles | Spanning Tree | PVST+ | show mac address-table | show vlan | show interfaces | EtherChannel | PortFast & BPDU Guard | Port Security | DHCP Snooping | Dynamic ARP Inspection | VLAN Configuration Lab | Inter-VLAN Routing Lab | Port Security Lab | DHCP Snooping & DAI Lab | Layer 2 Troubleshooting Lab