交換機上線不等於配置完成。接入層端口若不做安全加固、性能調優,就是隱患炸彈。本文給出生產環境可直接套用的 Cisco 風格配置模板,涵蓋 Access/Trunk 端口模板、關鍵特性原理、參數調優依據、驗證命令。
interface GigabitEthernet1/0/1 description ACCESS_PORT_TEMPLATE switchport mode access switchport access vlan 100 ! 業務 VLAN switchport port-security ! 端口安全 switchport port-security maximum 2 ! 最大 MAC 數 (終端+IP Phone/Hub) switchport port-security violation restrict ! 違規動作: restrict(告警+丟棄)/shutdown(關閉)/protect(丟棄不告警) switchport port-security aging time 30 ! 老化時間 30 分鐘 switchport port-security aging type inactivity spanning-tree portfast ! 端口快速進入 Forwarding (跳過 Listening/Learning ~30s) spanning-tree bpduguard enable ! 收到 BPDU 立即 Err-Disable (防私接交換機/環路) storm-control broadcast level 1.00 ! 廣播風暴抑制: 1% 帶寬閾值 (視業務調整 0.5-5%) storm-control multicast level 2.00 ! 組播風暴抑制 storm-control unicast level 5.00 ! 未知單播風暴抑制 storm-control action trap ! 超閾值發送 SNMP Trap 告警 ip dhcp snooping limit rate 10 ! DHCP 報文速率限制 10 pps (防 DHCP 耗盡攻擊) authentication port-control auto ! 802.1X/MAB 認證 (配合 AAA/RADIUS) dot1x pae authenticator mab ! MAC 認證旁路 authentication priority dot1x mab ! 優先 802.1X 再 MAB authentication order dot1x mab no shutdown
interface GigabitEthernet1/0/24 description UPLINK_TO_CORE switchport trunk encapsulation dot1q switchport mode trunk switchport trunk allowed vlan 10,20,30,100,200 ! 僅允許業務 VLAN,拒絕 VLAN 1 默認 switchport trunk native vlan 999 ! 原生 VLAN 改為未使用 ID,防 VLAN Hopping spanning-tree link-type point-to-point ! 點對點鏈路,RSTP 快速收斂 channel-group 1 mode active ! LACP 主動模式聚合 (Port-Channel 1) ip dhcp snooping trust ! 信任端口:允許 DHCP Server 回應 (Option 82 插入) ip arp inspection trust ! DAI 信任:允許 ARP 回應 no shutdown
interface Port-channel1 description CORE_AGGREGATION switchport trunk encapsulation dot1q switchport mode trunk switchport trunk allowed vlan 10,20,30,100,200 spanning-tree link-type point-to-point lacp min-links 1 ! 最小活躍鏈路數,防單鏈路帶寬不足 lacp fast-switchover ! 快速切換 (<50ms) no shutdown
! VTP 透明模式 (防誤刪 VLAN) vtp mode transparent ! DHCP Snooping 全局啟用 + 信任上聯 ip dhcp snooping ip dhcp snooping vlan 10,20,30,100,200 ip dhcp snooping information option ! Option 82 (Circuit ID + Remote ID) ip dhcp snooping database flash:/dhcp_snoop.db write-delay 300 ! 綁定表持久化 ! Dynamic ARP Inspection (DAI) ip arp inspection vlan 10,20,30,100,200 ip arp inspection validate src-mac dst-mac ip ! IP Source Guard (IPSG) - 防 IP 盜用 ! 接口下: ip verify source port-security ! 端口安全違規自動恢復 (可選) errdisable recovery cause psecure-violation bpduguard link-flap dhcp-rate-limit arp-inspection errdisable recovery interval 300 ! 設備基線 service timestamps debug datetime msec localtime show-timezone service timestamps log datetime msec localtime show-timezone logging buffered 512000 logging host 10.1.1.100 transport udp 514 ! Syslog 服務器 snmp-server community READ_ONLY RO snmp-server community READ_WRITE RW snmp-server enable traps snmp linkdown linkup coldstart warmstart snmp-server enable traps storm-control snmp-server enable traps errdisable ntp server 10.1.1.101 prefer clock timezone CST 8 0
! 入站 ACL 應用於 Trunk 入口 (或管理 VLAN SVI 入口) ip access-list extended ACL_IN_FROM_INTERNET deny tcp any any eq 3389 log ! 封鎖 RDP 暴力破解 deny tcp any any eq 445 log ! 封鎖 SMB (永恆之藍) deny tcp any any eq 1433 log ! 封鎖 MSSQL deny udp any any eq 1434 log ! 封鎖 SQL Browser permit ip any any ! 隱性 deny all,顯式 permit 便於統計 ! 管理平面保護 (Control Plane Policing - CoPP) ip access-list extended COPP_MGMT permit udp any any eq 161 ! SNMP permit udp any any eq 123 ! NTP permit tcp any any eq 22 ! SSH permit tcp any any eq 443 ! HTTPS permit icmp any any echo-reply ! Ping 回應 permit icmp any any ttl-exceeded ! Traceroute deny ip any any log ! 默認拒絕其它 control-plane service-policy input COPP_POLICY
| 目的 | 命令 |
|---|---|
| 查看端口安全狀態/違規計數 | show port-security interface Gi1/0/1 |
| 查看風暴控制狀態/計數 | show storm-control interface Gi1/0/1 |
| 查看 STP 狀態/端口角色/代價 | show spanning-tree interface Gi1/0/1 detail |
| 查看 DHCP Snooping 綁定表 | show ip dhcp snooping binding |
| 查看 DAI 統計/違規 | show ip arp inspection statistics vlan 100 |
| 查看 IPSG 綁定 | show ip verify source interface Gi1/0/1 |
| 查看 Port-Channel 狀態/負載 | show etherchannel 1 summary / detail |
| 查看 ACL 命中計數 | show access-lists ACL_IN_FROM_INTERNET |
| 查看 Err-Disable 端口/恢復定時器 | show errdisable recovery / show interfaces status err-disabled |
交換機接口優化不是「配完即棄」,而是標準模板化部署 + 持續遙測監控 (SNMP/Telemetry/NetFlow) + 定期審計合規。將上述模板納入網絡基線配置庫 (GitOps 管理),新設備上線自動推送,變更走 PR 審核,故障按 Runbook 流程處理,才能構建真正穩定、安全、可演進的網絡基礎設施。