Cyber Services / All lessons / Diploma in Network Technology / Switch Operations & Security

Switch Operations & Security

Module 16 of 36 · 4 min read · Free to read

MODULES ↓ Command blocks have a COPY button

Your Gateway to a Career in Network Engineering

Switch Operations: MAC Address Tables and Port Security

A Layer 2 switch is far more intelligent than a hub. Its intelligence comes from its ability to learn where devices are located and its ability to enforce security rules on its ports. This section explores the two fundamental operations that define modern switching: the dynamic MAC address table and the crucial security feature of Port Security.

The MAC Address Table: A Switch's Brain

The **MAC address table** (sometimes called a CAM table) is the heart of a switch's operation. It's a dynamically built list that maps every known device's MAC address to the specific switch port it's connected to. This table allows the switch to forward frames directly to their destination instead of blindly flooding them everywhere.

How a Switch Builds its MAC Address Table

  1. Learning: When a frame enters a port, the switch inspects the **source MAC address**. It adds this MAC address and the incoming port number to its table. This is how it learns the location of devices.
  2. Forwarding or Flooding: The switch then inspects the **destination MAC address**.
    • If the destination MAC is found in the table, the switch forwards the frame **only** to the associated port. This is a known **unicast**.
    • If the destination MAC is NOT in the table, the switch **floods** the frame out all other ports. This is an **unknown unicast**.
    • If the destination MAC is a broadcast address (FFFF.FFFF.FFFF), the switch **floods** it out all other ports.

Verification: `show mac address-table`

You can view a switch's MAC address table from the CLI to see what it has learned.

Switch# show mac address-table
          Mac Address Table
-------------------------------------------
Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
 10     000c.29a1.b445    DYNAMIC     Gi0/1
 10     000c.29e2.c556    DYNAMIC     Gi0/2
 20     aabb.cc00.0100    STATIC      Gi0/5

Here, the switch has dynamically learned two MAC addresses on VLAN 10 and has one statically configured MAC on VLAN 20.

Port Security: A Switch's Bouncer

An open, unconfigured switch port is a security risk. Anyone could walk up, plug in a laptop, and gain access to your network. **Port Security** is a feature that protects against this by controlling which devices are allowed to connect to a port.

It works by limiting the number of MAC addresses that can be learned on a specific interface. If an unauthorized device connects, Port Security will take a pre-configured action.

Three Components of Port Security Configuration:

  1. Maximum Allowed MAC Addresses: Sets a limit. For an access port connecting to a single PC, this should almost always be `1`.
  2. MAC Address Learning Method:
    • Static: You manually type in the allowed MAC address. Highly secure, but not scalable.
    • Dynamic: The switch learns the first MAC address it sees on the port and allows it. Simple, but the "allowed" MAC changes if the switch reboots.
    • Sticky: The switch learns the first MAC address dynamically, but then it "sticks" it to the configuration as if it were statically configured. **This is the most common and recommended method.**
  3. Violation Mode (What to do when an intruder connects):
    • Shutdown (Default): The port is immediately disabled and placed in an `err-disabled` state. An administrator must manually re-enable it. **This is the most secure mode.**
    • Restrict: The port drops traffic from the unauthorized MAC address but remains active. It sends a security alert (log/SNMP trap) and increments a violation counter.
    • Protect: The port drops traffic from the unauthorized MAC but does so silently, without sending any alerts or incrementing the counter. This mode is rarely used as it provides no visibility into security events.

Port Security Configuration Example (Best Practice)

Switch# configure terminal
Switch(config)# interface GigabitEthernet0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security          ! Enable Port Security
Switch(config-if)# switchport port-security maximum 1  ! Allow only 1 MAC address
Switch(config-if)# switchport port-security mac-address sticky ! Learn the first MAC and save it
Switch(config-if)# switchport port-security violation shutdown ! Shut down the port on violation
Switch(config-if)# end

Verification: `show port-security interface`

This command shows the status of Port Security on a specific interface.

Switch# show port-security interface Gi0/1
Port Security              : Enabled
Port Status                : Secure-up
Violation Mode             : Shutdown
Maximum MAC Addresses      : 1
Total MAC Addresses        : 1
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 1
Last Source Address:VlanId : 000c.29a1.b445:10
Security Violation Count   : 0
Modules (36) ← Diploma in Network Technology