Jun
26

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.

tclsh
puts [ open "flash:blank.cfg" w+] {
version 15.4
!
end
}
tclquit

An example implementation of this is as follows:

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

R1#tclsh
R1(tcl)#puts [ open "flash:blank.cfg" w+] {
+>(tcl)#version 1.1
+>(tcl)#!
+>(tcl)#end
+>(tcl)#}
R1(tcl)#tclquit
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.

*snip*

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

Router#

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!

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

Brian McGahan was one of the youngest engineers in the world to obtain the CCIE, having achieved his first CCIE in Routing & Switching at the age of 20 in 2002. Brian has been teaching and developing CCIE training courses for over 10 years, and has assisted thousands of engineers in obtaining their CCIE certification. When not teaching or developing new products Brian consults with large ISPs and enterprise customers in the midwest region of the United States.

Find all posts by Brian McGahan, CCIE #8593, CCDE #2013::13 | Visit Website


You can leave a response, or trackback from your own site.

6 Responses to “Erasing IOS Config with TCL and Config Replace”

 
  1. Juan Figueroa says:

    Thank you for sharing quality

  2. Mitch says:

    Very cool! TCL doesn’t get enough shout outs given the automation power it has, especially when coupled with Expect. This will be a great time saver when labbing. Thanks!

  3. Keenan Padgett, CCIE #39076 says:

    LOL , who would’ve known that you could do this but INE

  4. Keith says:

    This is soooooooooooooo awesome~!! Thx, Brian.

  5. Pablo says:

    Be careful when using this blank configuration with the csr1000v. If you reload the device, everything will go to default. You’ll loose access to your serial console. The default is to send the output to the ESX virtual console. To get it working again use “platform console serial” in global configuration mode and reload the device.

 

Leave a Reply

Categories

CCIE Bloggers