你是否也曾经碰到过,对Cisco路由器或者交换机进行了修改,然后又需要将这些修改移除掉的情况?有很多种方法可以完成这一点,但是哪种方式才是最简单,最安全的呢?重启路由器或者交换机并不是正确答案。实际上,只需使用一个简单的命令,效果却好得多。
假设你在一个路由器上已经实施了某些修改,生成了一个巨大的配置文件。 可能在进行修改的同时,你已经发现了有些地方不对劲,而等到进行测试时,期望的新功能的确也没发挥作用。
你现在所希望的就是将一切恢复原状,然后再从头开始。 该怎么做才能达到这一点呢?你有几个选择。
如果你还没保存这个配置,那么只要简单的重启路由器即可。 这是有用的,但是你肯定不希望自己不得不重启一台产品路由器。 另外,在没有必要的时候,你又何必去重启一台路由器,然后坐在一边傻傻等待呢?
你也可以使用copy startup-config running-config命令。不过,这个命令所做的事情,可能并不会像你所想象的那样。它只是将startup-config中的命令,和running-config中的命令合并起来。
如果有冲突的话,它会将命令留在running-config之中。 结果,你最后得到的,就是一个两种配置的混合物。 另外,它可能也会因为将老配置和修改配置的混合,而产生了一些不可预期的结果,最终导致出现一些路由器停工或瘫痪的现象。
如 何才能在不出现停工现象的情况下,恢复初始的startup-config配置呢? 这个问题的答案就是“configure replace”命令。 这个命令会将running-config和要替换的配置进行比较。 它会找出两个配置之间的不同,然后仅仅实施这些不同的部分。 这个命令对于没有改变过的配置,不会产生任何影响,而且它不会导致任何停工的出现。
一般情况下,你可以使用存放于路由器NVRAM中的startup-config(起始配置),来替换running-config(当前配置)。 要这么做,你需要执行下述命令:
configure replace nvram:startup-config
不 过,最后一个参数可以是任何一个有效的config文件,只要它是可接受的Cisco IOS URL格式。 比方说,这个config文件的实际存放地,可以是在某台TFTP, FTP, HTTP, RCP或者SCP服务器上。 这种情况下,命令可能就会变成下述这样:
configure replace tftp://192.168.1.107/config-bu
附 件A提供了一个使用Configure replace命令的基本示例。 首先,我关闭了我的FastEthernet4接口,然后我使用了configure replace nvram:startup-config命令,来用我的起始设置(startup-configuration)替换掉当前设置(running- configuration)。 虽然这是一个明显简化的示例,但是还是展现了命令的工作方式。
Configure replace命令是非常有用的——它常常能最小化停工时间,又能让你恢复到变化之前的起点。
附件A:
R1-871W#sh run int fa4
Building configuration...
Current configuration : 71 bytes
!
interface FastEthernet4
no ip address
duplex auto
speed auto
end
! shutting down the Fa4 interface
R1-871W#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1-871W(config)# int fa4
R1-871W(config-if)# shutdown
R1-871W(config-if)#^Z
R1-871W#
*Aug 10 13:06:43.269: %LINK-5-CHANGED: Interface FastEthernet4, changed state to administratively down
*Aug 10 13:06:43.273: %SYS-5-CONFIG_I: Configured from console by console
*Aug 10 13:06:44.269: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet4, changed state to down
R1-871W#
! verifying that the Fa4 interface is shutdown
R1-871W#sh run int fa4
Building configuration...
Current configuration : 81 bytes
!
interface FastEthernet4
no ip address
shutdown
duplex auto
speed auto
end
! replacing the current config with the saved config
R1-871W# configure replace nvram:startup-config
This will apply all necessary additions and deletions
to replace the current running configuration with the
contents of the specified configuration file, which is
assumed to be a complete configuration, not a partial
configuration. Enter Y if you are sure you want to proceed. ? [no]: y
*Aug 10 13:06:55.189: Rollback:Acquired Configuration lock.
Total number of passes: 1
Rollback Done
! notice the "rollback done" message and how the interface immediately started coming up (below)
R1-871W#
*Aug 10 13:06:59.245: %LINK-3-UPDOWN: Interface FastEthernet4, changed state to up
*Aug 10 13:07:00.245: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet4, changed state to up
R1-871W#
! verifying that the interface is now set to up
R1-871W# sh run int fa4
Building configuration...
Current configuration : 71 bytes
!
interface FastEthernet4
no ip address
duplex auto
speed auto
end
R1-871W#

