思科路由器密碼儲存在 NVRAM startup-config 中。啟動時,IOS 讀取配置寄存器決定是否載入 NVRAM 配置。將配置寄存器第 6 位(Bit 6)設為 1(值 0x2142),路由器啟動時會忽略 NVRAM 配置,直接載入預設空白配置進入特權模式,即可重設密碼。完成後將寄存器改回 0x2102 恢復正常啟動。
2500、2600、3600、3700、3800、2800、2900、3900、ISR 4000 等支援斷點中斷的平台。
不適用:Catalyst 交換器(需 Mode 鍵)、部分固定配置低端機型。
reload)。rommon 1 > 提示符,表示進入 ROM Monitor。rommon 1 > confreg 0x2142
You must reset or power cycle for new config to take effect
rommon 2 > reset
路由器重新啟動,跳過 NVRAM 配置,直接進入初始設定對話。
--- System Configuration Dialog ---
Would you like to enter the initial configuration dialog? [yes/no]: no
Press RETURN to get started!
輸入 no,按 Enter,出現 Router> 用戶模式提示符。
Router> enable
Router# copy startup-config running-config
Destination filename [running-config]? [Enter]
816 bytes copied in 0.884 secs
Router#
關鍵:此步驟將 NVRAM 中的舊配置(含介面 IP、路由協議、ACL 等)合併到運行配置,但密碼仍為舊密碼(加密雜湊)。若直接show running-config可見密碼雜湊,但無法反解。階段五:設定新密碼
Router# configure terminal Router(config)# enable secret New$tr0ngP@ss! Router(config)# enable password New$tr0ngP@ss! ! 相容舊版,建議同步設定 Router(config)# line console 0 Router(config-line)# login Router(config-line)# password Con$olePwd! Router(config-line)# exit Router(config)# line aux 0 Router(config-line)# login Router(config-line)# password Aux$tr0ngP@ss! Router(config-line)# exit Router(config)# line vty 0 4 Router(config-line)# login Router(config-line)# password VtyP@ss! Router(config-line)# transport input ssh Router(config-line)# exit Router(config)# config-register 0x2102 Router(config)# end Router# copy running-config startup-config Destination filename [startup-config]? [Enter] Building configuration... [OK] Router#階段六:驗證與重啟
Router# reload Proceed with reload? [confirm] [Enter] ! 重啟後以新密碼登入驗證關鍵指令對照表
階段 關鍵指令 用途 進入 Rommon Ctrl+Break 中斷啟動序列 修改寄存器 confreg 0x2142忽略 NVRAM 配置 重啟 reset套用新寄存器值 合併配置 copy startup-config running-config保留介面/路由等業務配置 設定新密碼 enable secret/line ... passwordMD5 加密特權密碼、線路密碼 恢復寄存器 config-register 0x2102正常啟動載入 NVRAM 存檔 copy run start寫入 NVRAM 生效 常見失敗原因與對策
- 無法進入 Rommon:終端機未正確送出 Break 訊號 → 確認終端機軟體設定、嘗試 Ctrl+] 後輸入
send break(Putty)、更換 USB 轉序列晶片(FTDI/CP2102 較穩定)。- 合併配置後介面 down:舊配置含
shutdown→ 逐一no shutdown或config-register 0x2102前批次開啟。- 重啟後密碼未生效:未執行
copy run start或寄存器未改回0x2102。- 忘記新密碼:重複上述流程,或使用配置備份還原。
安全建議
- 密碼恢復屬於高風險操作,需記錄操作人、時間、原因,納入變更管理。
- 完成後立即驗證新密碼、備份配置、更新密碼管理系統。
- 物理安全:機房門禁、Console 埠鎖定、AUX 埠停用或強密碼,防止未授權人員物理接觸執行密碼恢復。
- 部署 AAA + TACACS+/RADIUS 集中認證,減少本地密碼依賴。
結語
密碼恢復是網管必修課。熟練掌握
confreg 0x2142→copy start run→ 設新密 →config-register 0x2102→write mem完整鏈路,並在實驗環境反覆演練,才能在生產故障高壓下冷靜精準操作,將業務中斷時間壓縮至最低。