Cisco路由器从配置文件加载及恢复出厂设置

本文给出Cisco路由器从保存的配置加载,配置寄存器0x21020x2142的区别,以及路由器如何恢复出厂设置。

1. 保存路由器配置信息

在做OSPF配置实验时,修改路由器ID,保存配置(copy running-config startup-config),重新加载路由器reload,发现之前做的配置都没了,当然也包括Router ID。

这是因为实验室为了便于管理,让路由器每次都从ROM启动,而配置文件是保存在Non-Volatile RAM (NVRAM),解决办法是通过设置配置寄存器(R3(config)#config-register 0x2102)让路由器从NVRAM加载已保存的配置文件。具体做法如下:

Router>enable                               # 进入特权执行模式
Router#config t                             # 进入全局配置模式
Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#hostname R3                  # 修改路由器名称

R3(config)#config-register 0x2102           # 设置配置寄存器地址

R3#copy running-config startup-config       # 保存配置文件
Destination filename [startup-config]? 
Building configuration...

R3(config)#end

配置完,就可以重新加载路由器了,如下:

R3#reload
Proceed with reload? [confirm]

*Dec 13 02:40:53.175: %SYS-5-RELOAD: Reload requested by console. Reload Reason: Reload Command.

PS:Cisco Packet Tracer上路由器配置寄存器默认设为0x2102,每次启动(比如关机添加串口模块)都会加载配置文件,不存在上述问题。

2. 配置寄存器

2.1 配置寄存器

设置配置寄存器(configuration register)可以改变路由器的行为,包括[1]

  • how the router boots (into ROMmon, NetBoot)
  • options while booting (ignore configuration, disable boot messages)
  • console speed (baud rate for a terminal emulation session)

可以通过命令show version查看当前配置寄存器的值:

Router>show version
...          
Cisco CISCO2901/K9 (revision 1.0) with 475136K/49152K bytes of memory.
Processor board ID FGL201324AH
1 DSL controller
1 Ethernet interface
2 Gigabit Ethernet interfaces
2 Serial(sync/async) interfaces
1 ATM interface
1 terminal line
1 Virtual Private Network (VPN) Module
2 Voice FXS interfaces
DRAM configuration is 64 bits wide with parity enabled.
255K bytes of non-volatile configuration memory.
255488K bytes of ATA System CompactFlash 0 (Read/Write)


License Info:

License UDI:

-------------------------------------------------
Device#   PID                   SN
-------------------------------------------------
*1        CISCO2901/K9          FGL201324AH     



Technology Package License Information for Module:'c2900' 

------------------------------------------------------------------------
Technology    Technology-package                  Technology-package
              Current              Type           Next reboot  
------------------------------------------------------------------------
ipbase        ipbasek9             Permanent      ipbasek9
security      securityk9           Permanent      securityk9
uc            uck9                 Permanent      uck9
data          None                 None           None
NtwkEss       None                 None           None
CollabPro     None                 None           None

**Configuration register is 0x2142**

最后一行显示了配置寄存器的值为0x2142。在1中将配置寄存器设置为0x2102,再次用show version查看,可以看到下一次路由器将从0x2102加载。

R3#show version
...

Configuration register is 0x2142 (will be 0x2102 at next reload)

2.2 0x2142 vs 0x2102

思科路由器定义了13种配置寄存器的值,详情见:Use of the Configuration Register on All Cisco Routers – Cisco0x21420x2102是最常见的两种,前者忽略配置文件,后者从NVRAM加载配置文件。

0x2142

  • Ignores break
  • Boots into ROM if initial boot fails
  • 9600 console baud rate
  • Ignores the contents of Non-Volatile RAM (NVRAM) (ignores configuration)

0x2102

  • Ignores break
  • Boots into ROM if initial boot fails
  • 9600 console baud rate default value for most platforms
  • The default setting of config register. (IOS from Flash & startup-config from NVRAM)

3. 恢复出厂设置

具备了上述知识,现在可以解决忘记密码的问题。解决忘记密码问题通常是恢复出厂配置,家用路由器(比如tp-link)有个reset孔,通电后拿个针长按就可以了,但思科路由器恢复出厂配置需要通过命令完成。思路很简单,让路由器从ROM加载,开机之后,再保存配置文件,将之前的覆盖掉。具体做法如下:

终端连上路由器(比如用SecureCRT),路由器开机后,按Ctrl + Pause/Break进入恢复模式。用命令confreg 0x2142将配置路由器改为0x2142,再重置系统reset

rommon 1 > confreg 0x2142   # configuration register utility

You must reset or power cycle for new config to take effect

rommon 2 > reset        # system reset

References:

[1] Use of the Configuration Register on All Cisco Routers – Cisco

Leave a Reply

Your email address will not be published. Required fields are marked *