In a recent post I talked about Using Config Replace For Managing Router & Switch Initial Configs.  This is a great feature that can be useful to quickly switch between initial configs and a default config while labbing on your routers without having to write erase and reload - which can be very time consuming.  However, I previously assumed that this required a staged "blank" config in the router's flash, because regular IOS and IOS-XE don't have a built in text editor such as vi/nano/pico that would let you create a blank file on the router's flash.

Thanks to my buddy xous in #cisco on irc.freenode.net, I found that you can use TCL to write a file to flash through the IOS CLI, the same as if it was a native text editor.  The end result is that you can use the following code to write a blank config file at any time to rollback to.

puts [ open "flash:blank.cfg" w+] {
version 15.4

An example implementation of this is as follows:

R1#show ip int brief | exclude unassign
Interface IP-Address OK? Method Status Protocol
GigabitEthernet1.13 YES TFTP up up
GigabitEthernet1.100 YES TFTP up up
GigabitEthernet1.146 YES TFTP up up
Loopback0 YES TFTP up up
Tunnel0 YES TFTP up up

R1(tcl)#puts [ open "flash:blank.cfg" w+] {
+>(tcl)#version 1.1
R1#config replace flash:blank.cfg
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]: yes
Overwriting with a file sized 50% or less than running config's. Proceed? [no]: yes
% Be sure to ask the CA administrator to revoke your certificates.


Router#show ip int brief | ex unassign
Interface IP-Address OK? Method Status Protocol


The end result is that you can at any time default the router's config without having to erase and reload. Note that there are certain caveats such as deleted subinterfaces on Ethernet or Serial links which will still exist as "deleted" in the running config, but in most cases for our applications this will not be an issue.

Also as a shameless plug for IRC feel free to join the discussion in the channel #cisco on irc.freenode.net and chat with us. You can find me there with nick bmcgahan.

Happy labbing!

Brian McGahan, CCIE #8593, CCDE #2013::13
About Brian McGahan, CCIE #8593, CCDE #2013::13

At the age of 20, Brian McGahan earned his first CCIE in Routing & Switching, and became known as the “youngest engineer in the world.” He continued on to earn CCIE certifications in Security, Service Provider, and Data Center. Brian has developed and taught for INE since 2002, setting the bar for CCIE training and helping thousands of engineers obtain their own certifications--we’re proud to have such an accomplished and driven instructor on the INE team. When he is not developing new products for INE, he consults with large ISPs and enterprise customers. You may contact Brian McGahan at bmcgahan@ine.com or find him helping others in INE’s IEOC Community Forum.

Subscribe to INE Blog Updates

New Blog Posts!