多網管同時配置同一台路由器時,易發生配置丟失、部分生效、運行配置與啟動配置不一致等問題。Cisco IOS 引入 Configuration Lock (配置鎖),提供排他性會話鎖定、自動/手動模式、超時保護、命令執行可視化、回滾功能,實現配置變更的序列化與可審計。本文詳細解析命令語法、兩種模式操作、show 輸出解讀、回滾機制與最佳實踐。
Router(config)# configuration mode exclusive {auto | manual} [expire seconds] [lock-show] [interleave] [terminate] [config_wait seconds] [retry_wait seconds]
| 參數 | 含義 | 建議 |
|---|---|---|
| auto / manual | 自動模式:進入全局配置模式即自動獲鎖 / 手動模式:需显式 configure terminal lock | 推薦 auto,零感知保護 |
| expire seconds | 鎖超時自動釋放時間 (秒) | 默認 600s,建議 300-600s,防網管忘記退出佔用 |
| lock-show | 顯示鎖狀態信息 | 開啟 |
| interleave | 允許非配置命令 (show 等) 穿插執行 | 開啟,不阻礙排查 |
| terminate | 強制終止其他會話的配置鎖 | 緊急情況謹慎使用 |
| config_wait / retry_wait | 等待獲鎖/重試間隔 | 默認即可 |
Router(config)# configuration mode exclusive auto
之後每次 configure terminal 自動獲取排他鎖,其他管理員嘗試進入配置模式將報錯:
Router# configure terminal
Configuration mode is locked by user 'admin' on vty 0 (192.168.1.50)
Configuration mode is exclusive, cannot enter configuration mode.
Router# configure terminal lock
Enter configuration commands, one per line. End with CNTL/Z
Router(config)# ... 進行配置 ...
Router(config)# end (或 Ctrl+Z) 釋放鎖
忘記 lock 關鍵字將無法獲鎖,同樣會被自動模式持有者阻擋。
Router(config)# show configuration lock
Parser Configure Lock
Owner PID: 10
User : User3
TTY : 3
Type : EXCLUSIVE
State: LOCKED
Class: Exposed
Count: 0
Pending Requests : 0
User debug info : 0
Router# show configuration lock
Parser Configure Lock
-----------------------------
Owner PID : 3
User : unknown
TTY : 0
Type : EXCLUSIVE
State : LOCKED
Class : EXPOSED
Count : 1
Pending Requests : 0
User debug info : configure terminal
Session idle state: TRUE
No of exec cmds getting executed : 0
No of exec cmds blocked : 0
Config wait for show completion : FALSE
Remote ip address : Unknown
Lock active time (in Sec) : 6
Lock Expiration timer (in Sec): 593
關鍵字段:User (持有者)、TTY (會話)、Lock active time (持鎖時長)、Lock Expiration timer (剩餘超時)。
configure replace (全量替換啟動配置),獨佔鎖回滾 僅在持鎖會話內將運行配置恢復為獲鎖時的快照interleave 允許 show 命令