Cisco 路由器密碼體系包含特權密碼、Console/AUX/VTY 線路密碼、服務加密與報文過濾。正確配置可構建纵深防禦。本文整理標準配置流程、指令效果對照、加密類型差異與進階防火牆過濾範例。
! 1. 進入 Rommon 修改寄存器 (遺失密碼時)
rommon> confreg 0x2142
rommon> reset
! 2. 跳過 Setup,合併配置
Router> enable
Router# copy startup-config running-config
Router# configure terminal
! 3. 設定主機名與特權密碼
Router(config)# hostname R1
Router(config)# no enable secret
Router(config)# no enable password
Router(config)# enable secret S3cr3tP@ss2024
Router(config)# enable password Cisco123 ! 僅作相容舊版,實際無效
! 4. 線路密碼
Router(config)# line console 0
Router(config-line)# password ConP@ss2024
Router(config-line)# login
Router(config-line)# logging synchronous
Router(config-line)# exec-timeout 5 0
Router(config)# line vty 0 4
Router(config-line)# password VtyP@ss2024
Router(config-line)# login local
Router(config-line)# transport input ssh
! 5. 關閉 DNS 查找、加密服務、恢復寄存器
Router(config)# no ip domain-lookup
Router(config)# service password-encryption
Router(config)# config-register 0x2102
Router(config)# end
Router# write memory
Router# reload
| 指令 | 功能 | 加密類型 | 備註 |
|---|---|---|---|
line console 0 | 控制台終端密碼 | Type 7 (可逆) | 實體存取控制 |
line vty 0 4 | Telnet/SSH 遠端密碼 | Type 7 | 建議 login local + SSH |
enable password | 特權模式舊式密碼 | Type 7 | 有 Secret 時不生效 |
enable secret | 特權模式 MD5 密文 | Type 5 (不可逆) | **首選**,防離線破解 |
service password-encryption | 全域加密所有明文密碼 | Type 7 | 防配置檔肩窺,非高強度 |
僅允許管理網段 192.168.100.0/24 以 SSH 存取:
access-list 23 permit 192.168.100.0 0.0.0.255
line vty 0 4
access-class 23 in
transport input ssh
進階:針對特定協議/埠號過濾 (如僅允許 DNS 回應進入):
access-list 101 permit udp any host 192.168.1.1 eq domain
access-list 101 deny ip any any
interface Serial0/0
ip access-group 101 in
show run | include enable secret|service password 確認 Type 5 與加密服務啟用。login block-for)。show run | section line 確認 VTY 僅 transport input ssh。