萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 網路安全 >  >> 網路應用技術 >> 應用程式教學

交換器埠口安全完整指南:MAC 綁定、數量限制、違規模式與 802.1X 進階認證

埠口安全透過 MAC 位址控制流量,防止未授權裝置接入、限制單埠 MAC 數量、抵禦 MAC 泛洪攻擊。進階可部署 802.1X 基於埠口的網路存取控制 (NAC)。以 Catalyst 3550 為例說明。

一、MAC 位址綁定與數量限制 (允許清單模式)

# 進入介面配置模式
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 觸發違規動作。

二、Trunk 埠限制 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。

三、MAC 位址過濾 (拒絕清單模式)

# 僅對單播有效,多播無效
# 在特定 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

四、安全 MAC 位址學習機制

  • 靜態配置: switchport port-security mac-address
  • 動態學習: 從已連接裝置自動學習 (未達上限前)
  • 黏滯學習: switchport 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不發送不增加自動

六、配置限制條件 (必讀)

  • ❌ 不能在動態 Access/Trunk 埠配置 (需先 switchport mode access/trunk)
  • ❌ 不能在 Protected Port 配置
  • ❌ 不能作為 SPAN 目的地
  • ❌ 不能屬於 EtherChannel (GEC/FEC) 群組
  • ❌ 不能與 802.1X 共存,互斥報錯

七、802.1X 基於埠口的網路存取控制 (推薦方案)

優於 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 綁定雙重防護。

copyright © 萬盛學電腦網 all rights reserved