blog
    Erasing IOS Config with T ...
    27 June 14

    Erasing IOS Config with TCL and Config Replace

    Posted byBrian McGahan
    facebooktwitterlinkedin
    news-featured

    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!

    Hey! Don’t miss anything - subscribe to our newsletter!

    © 2022 INE. All Rights Reserved. All logos, trademarks and registered trademarks are the property of their respective owners.
    instagram Logofacebook Logotwitter Logolinkedin Logoyoutube Logo