埠口安全透過 MAC 位址控制流量,防止未授權裝置接入、限制單埠 MAC 數量、抵禦 MAC 泛洪攻擊。進階可部署 802.1X 基於埠口的網路存取控制 (NAC)。以 Catalyst 3550 為例說明。
# 進入介面配置模式
Switch(config)# interface fastethernet 0/1
# 設定為 Access 模式 (必要前置)
Switch(config-if)# switchport mode access
# 綁定特定 MAC (可重複指令綁定多組)
Switch(config-if)# switchport port-security mac-address 00-90-F5-10-79-C1
# 限制最大安全 MAC 數 (預設 1)
Switch(config-if)# switchport port-security maximum 1
# 違規行為:shutdown (預設) / protect / restrict
Switch(config-if)# switchport port-security violation shutdown
效果: 僅允許綁定 MAC 通過,其他 MAC 觸發違規動作。
Switch(config)# interface fastethernet 0/1
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport port-security maximum 100
Switch(config-if)# switchport port-security violation protect
效果: 最多 100 組 MAC,超過者封包丟棄、介面維持 Up、不發送 SNMP Trap。
# 僅對單播有效,多播無效
# 在特定 VLAN 丟棄該 MAC 流量
Switch(config)# mac-address-table static 00-90-F5-10-79-C1 vlan 2 drop
# 或在特定介面丟棄
Switch(config)# mac-address-table static 00-90-F5-10-79-C1 vlan 2 interface fastethernet 0/1
switchport port-security mac-addressswitchport port-security mac-address sticky 將動態學習轉為靜態配置埠口 shutdown 時,所有動態學習 MAC 會被移除。
| 模式 | 行為 | SNMP Trap | 計數器 | 恢復方式 |
|---|---|---|---|---|
| shutdown (預設) | 介面立即 err-disable | 發送 | 增加 | errdisable recovery cause psecure-violation 或手動 shutdown/no shutdown |
| restrict | 丟棄違規封包,介面維持 Up | 發送 | 增加 | 自動 (移除多餘 MAC 後恢復) |
| protect | 丟棄違規封包,介面維持 Up | 不發送 | 不增加 | 自動 |
switchport mode access/trunk)優於 MAC 綁定:支援使用者層級認證、動態 VLAN 指派、集中管理、防偽裝 MAC。
# 全域啟用 AAA
Switch(config)# aaa new-model
# 802.1X 使用本地資料庫認證 (生產環境建議 RADIUS)
Switch(config)# aaa authentication dot1x default local
# 全埠啟用 802.1X (建議所有存取埠)
Switch(config)# interface range fastethernet 0/1 - 24
Switch(config-if-range)# dot1x port-control auto
建議: 生產環境部署 802.1X + RADIUS (NPS/ISE/FreeRADIUS) 管理帳號,關鍵基礎設施埠口保留 MAC 綁定雙重防護。