萬盛學電腦網

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

Cisco交換機配置實戰速成:從基礎管理到端口進階全流程

CLI 操作基礎與高效技巧

  • 模式切換: User EXEC (`>`) → `enable` → Privileged EXEC (`#`) → `configure terminal` → Global Config (`(config)#`) → Interface Config (`(config-if)#`)。
  • 命令縮寫: 唯一前綴即可,如 `en`=`enable`、`conf t`=`configure terminal`、`sh run`=`show running-config`。
  • Tab 補全 / `?` 幫助 / `Ctrl+Z` 回特權 / `Up/Down` 歷史指令。
  • 編輯熱鍵: `Ctrl+A`(行首) `Ctrl+E`(行尾) `Ctrl+W`(刪詞) `Ctrl+U`(刪行) `Ctrl+R`(重顯)。

基礎管理配置清單

hostname SW-CORE-01
enable secret cisco123        // 加密特權密碼 (最高優先)
enable password cisco         // 明文密碼 (舊版相容)
no ip domain-lookup           // 關閉域名解析防輸入錯誤卡頓
line vty 0 15
 password class
 login
 transport input ssh         // 僅允許 SSH
line console 0
 logging synchronous         // 防日志打斷輸入
exec-timeout 10 0
service password-encryption   // 全域加密明文密碼

管理面 IP 與預設閘道

interface vlan 10
 ip address 192.168.10.2 255.255.255.0
 no shutdown
ip default-gateway 192.168.10.254
ip name-server 8.8.8.8 114.114.114.114
ip domain-name corp.local

注意: SVI (VLAN 介面) IP 僅供管理,不影響數據平面轉發。若為三層交換機,建議用 Loopback 做管理環回口。

端口屬性精準控制

interface range GigabitEthernet1/0/1 - 24
 description ACCESS_USER_PORT
 speed 1000
 duplex full
 spanning-tree portfast            // 端口直進 Forwarding,跳過 Listening/Learning
 spanning-tree bpduguard enable    // 收到 BPDU 自動 Err-disable,防私接交換機
 switchport mode access
 switchport access vlan 10
 switchport nonegotiate            // 強制 Access,不發 DTP
 authentication port-control auto  // 802.1X/MAB 準入 (可選)
 no shutdown

Trunk 乾道配置與 VLAN 修剪

interface TenGigabitEthernet1/1/1
 description UPLINK_TO_CORE
 switchport trunk encapsulation dot1q
 switchport mode trunk
 switchport trunk allowed vlan 10,20,30,100   // 僅允許必要 VLAN,減少廣播洪泛
 switchport trunk native vlan 999             // 原生 VLAN 改非預設,防 VLAN Hopping
 channel-group 1 mode active                  // LACP 聚合
 spanning-tree link-type point-to-point

驗證與排錯黃金指令

目的指令
查看介面狀態/速率/錯誤計數`show interfaces status` / `show interfaces gi1/0/1 counters errors`
查看 VLAN 簡介/端口隸屬`show vlan brief` / `show interfaces trunk`
查看生成樹狀態/根橋`show spanning-tree` / `show spanning-tree root`
查看鄰居/拓撲`show cdp neighbors detail` / `show lldp neighbors`
即時抓封包 (嵌入式 Wireshark)`monitor capture CAP1 interface gi1/0/1 both` → `monitor capture CAP1 start` → `show monitor capture CAP1 buffer brief`

最佳實務備忘

  1. 配置前 `write erase` + `reload` 乾淨起步;配置後 `write memory` (或 `copy run start`)。
  2. 善用 `interface range` 批量配置,配合 `macro` 套用樣板。
  3. 所有管理流量走專用 OOB (Out-of-Band) 網路或獨立 VRF。
  4. 啟用 `logging buffered 51200`、`logging trap notifications`、NTP 對時、SNMPv3 監控。
copyright © 萬盛學電腦網 all rights reserved