網絡工程師必備 Cisco 交換機 (2960/3560/3750/4500/9000 等) 高頻配置命令速查表,涵蓋基礎管理、IP 管理、端口速率雙工、開關端口、VLAN/Trunk、Port Security、DHCP Snooping、STP、EtherChannel 等核心場景,適合實戰速查與考證復習。
Switch> 用戶模式 (僅查看) Switch> enable 進入特權模式 Switch# 特權模式 (查看/調試/保存/升級) Switch# configure terminal 進入全局配置模式 Switch(config)# 全局配置模式 Switch(config)# interface fa0/1 進入接口配置模式 Switch(config-if)# 接口配置模式 Switch(config-if)# exit 返回全局 Switch(config)# exit 返回特權 Switch# write memory / copy running-config startup-config 保存配置
Switch(config)# hostname SW-CORE 設置主機名 Switch(config)# enable secret cisco123 設置加密特權密碼 (推薦) Switch(config)# enable password cisco 設置明文密碼 (不推薦) Switch(config)# no ip domain-lookup 關閉域名解析 (防輸入錯誤卡頓) Switch(config)# line console 0 Switch(config-line)# password console123 設置 Console 密碼 Switch(config-line)# login 啟用登入驗證 Switch(config-line)# logging synchronous 防止日誌打斷輸入 Switch(config-line)# exec-timeout 0 0 取消超時登出 (0=永不) Switch(config)# line vty 0 4 配置 VTY 遠程登入 (Telnet/SSH) Switch(config-line)# password vtypass Switch(config-line)# login Switch(config-line)# transport input ssh 僅允許 SSH (安全) Switch(config)# ip domain-name lab.local SSH 需域名 Switch(config)# crypto key generate rsa modulus 2048 生成 RSA 密鑰 Switch(config)# ip ssh version 2 強制 SSH v2
Switch(config)# interface vlan 10 進入 VLAN 10 三層接口 (SVI) Switch(config-if)# ip address 192.168.10.1 255.255.255.0 Switch(config-if)# no shutdown 啟用接口 Switch(config-if)# exit Switch(config)# ip default-gateway 192.168.10.254 二層交換機設置默認網關 (三層交換機用 ip route)
! 速率/雙工 (銅口) Switch(config-if)# speed 10 / 100 / 1000 / auto Switch(config-if)# duplex half / full / auto ! 千兆光口 (GBIC/SFP) 通常不支持 speed/duplex,可用 nonegotiate 強制不協商 ! 開關端口 Switch(config-if)# shutdown 關閉 (Admin Down) Switch(config-if)# no shutdown 開啟 (Up) ! 驗證 Switch# show interfaces fa0/1 status Switch# show interfaces fa0/1 counters errors
! 創建 VLAN (全局模式) Switch(config)# vlan 10 Switch(config-vlan)# name Management Switch(config-vlan)# exit ! Access 端口 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 10 ! Trunk 端口 Switch(config-if)# switchport trunk encapsulation dot1q Switch(config-if)# switchport mode trunk Switch(config-if)# switchport trunk allowed vlan 10,20,30 Switch(config-if)# switchport trunk native vlan 99 ! 動態協商 (不推薦生產環境) Switch(config-if)# switchport mode dynamic desirable / auto ! 驗證 Switch# show vlan brief Switch# show interfaces trunk Switch# show interfaces fa0/1 switchport
Switch(config-if)# switchport mode access Switch(config-if)# switchport port-security Switch(config-if)# switchport port-security maximum 2 最大學習 2 個 MAC Switch(config-if)# switchport port-security violation restrict 違規動作: restrict(丟包+日誌)/shutdown(關閉端口)/protect(僅丟包) Switch(config-if)# switchport port-security mac-address sticky 動態學習並固化到運行配置 Switch(config-if)# switchport port-security mac-address 00:11:22:33:44:55 手動綁定靜態 MAC Switch(config-if)# switchport port-security aging time 30 老化時間 30 分鐘 Switch(config-if)# switchport port-security aging type inactivity 非活動老化 ! 驗證 Switch# show port-security interface fa0/1 Switch# show port-security address
! 全局啟用 Switch(config)# ip dhcp snooping Switch(config)# ip dhcp snooping vlan 10,20 Switch(config)# no ip dhcp snooping information option 關閉 Option 82 (視情況) ! 信任端口 (上行/服務器端口) Switch(config-if)# ip dhcp snooping trust Switch(config-if)# ip dhcp snooping limit rate 100 限制 DHCP 報文速率 ! 動態 ARP 檢測 (DAI) Switch(config)# ip arp inspection vlan 10,20 Switch(config-if)# ip arp inspection trust 信任端口不檢查 Switch(config-if)# ip arp inspection limit rate 50 ! IP Source Guard (綁定 IP+MAC+VLAN+端口) Switch(config-if)# ip verify source port-security ! 驗證 Switch# show ip dhcp snooping Switch# show ip dhcp snooping binding Switch# show ip arp inspection vlan 10
Switch(config)# spanning-tree mode rapid-pvst 啟用 RSTP (快速收斂) Switch(config)# spanning-tree vlan 10 priority 4096 設為根橋 (優先級 4096 的倍數) Switch(config)# spanning-tree portfast default 全局啟用 PortFast (接入口) Switch(config)# spanning-tree portfast bpduguard default 全局啟用 BPDU Guard Switch(config-if)# spanning-tree portfast 接口級啟用 Switch(config-if)# spanning-tree bpduguard enable Switch(config-if)# spanning-tree guard root Root Guard 防止錯誤根橋 ! 驗證 Switch# show spanning-tree vlan 10 detail
! 接口範圍批量配置 Switch(config)# interface range fa0/1 - 2 Switch(config-if-range)# channel-group 1 mode active LACP 主動模式 Switch(config-if-range)# switchport mode trunk Switch(config-if-range)# switchport trunk allowed vlan 10,20 Switch(config-if-range)# exit ! 驗證 Switch# show etherchannel summary Switch# show interfaces port-channel 1
| 命令 | 用途 |
|---|---|
show running-config | 查看當前運行配置 |
show startup-config | 查看啟動配置 (NVRAM) |
show version | IOS 版本、硬件、運行時間、配置寄存器 |
show interfaces [id] [status/counters/errors] | 接口狀態/流量/錯誤計數 |
show ip interface brief | 所有三層接口 IP/狀態一覽 |
show mac address-table [dynamic/static] | MAC 地址表 |
show vlan [brief/id] | VLAN 信息 |
show spanning-tree [vlan id] [detail] | 生成樹狀態 |
show etherchannel summary | 聚合組狀態 |
show logging | 系統日誌 |
show processes cpu [history] | CPU 佔用/歷史趨勢 |
show memory [statistics] | 內存使用 |
命令無數,核心幾類:模式切換、基礎設置、IP/SVI、端口屬性、VLAN/Trunk、安全 (Port Security/DHCP Snooping/DAI)、STP、聚合、Show 診斷。熟練這套組合拳,配置排錯雙全。實驗環境多練
do show ...在配置模式下直接看狀態,效率倍增。