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!

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.

13 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. Mattias says:

    Tried to manually do a config replace on a CSR 1000v running csr1000v-universalk9.03.12.00.S.154-2.S-std.SPA.bin and it dumped core and rebooted :-/

  6. 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.

  7. ShawnC says:

    This is a good tip, but since, each chapter of the workbook generally requires the same base config. I just generally paste the INE configs into the router, then copy running-config flash:whatever.cfg.

    When I am ready for the next lab in the line; config replace flash:whatever.cfg. Seems to be working OK for now.

  8. KHEN says:

    Hey Brian,

    I was trying this before I saw your post. I do have a question though? Why can I not call config replace from TCLSH?

    ios_config “config replace ftp://x.x.x.x/R1.txt

    When I try to run this command in TCLSH, I get not errors, but the config is also not replaced.

  9. Nick Cutting says:

    In GNS3 where the reload is busted – this is some seriously awesome stuff. I’ve been looking for this file creation technique for a decade.

    Thank you ! Now I just hope my company renews my all access pass…

  10. Moustafa Kaid says:

    I used tcl in many other direction, it saves money as well!
    instead of being physically attached to devices in order to make major changes VPN, ISP IP’s, BGP Peers and IGP red. you can make the changes inside tclsh and apply and reload.
    like if you change public IP address remotely without loseing connectivity.

    Thanks a lot Brain for sharing!


Leave a Reply


CCIE Bloggers