Automation & Tools

SNMP Can Save Your Life

Locked out of a remote router by a bad VTY ACL, I used snmpset and the Cisco config copy MIB to pull its running-config over TFTP and push a fix back in.

Tony Mattke · 2011.09.28 · 3 min read

Ever get locked out of a router or switch that is many hours or even days away? Recently, I had the pleasure, again. For some reason, be it the consultant that was turning up our MLPPP session on site, the engineer who was working with the consultant, or a random case of configuration corruption…. a VTY access-class statement got changed to a non-existent ACL. But, at first, I didn’t know this. I didn’t know anything. I assumed the remote office was up, due to the lack of complaints, and the fact that I could get to the server and switch behind the router, but other than that, I had no clue.

After wasting time trying to figure out why we couldn’t get back into this router, I decided to look into solving our issue with SNMP. I found the Cisco OID‘s for making copying configurations and devised a plan. This simple bash script will instruct the router to copy its running-config to the TFTP Server of your choice. Simply change the variables to match your Read/Write SNMP Community String, Remote Device IP, your TFTP Server’s IP, and the destination filename.

bash
#!/bin/bash
STRING=private
IP=10.8.4.1
TFTP=10.0.1.200
FILENAME=SiteXYZ-Config
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 6
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.111 i 1
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 1
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a $TFTP
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s $FILENAME
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1

Once you run this script, you will find the configuration stored in your TFTP directory. If you’re having issues, ensure you have full reachability to the default source interface of the router… You should be able to find the issue preventing you from accessing the router, in our case it was a bad VTY ACL. To remedy this, I created a dummy config file with the changes I wanted to make. For demonstrative purposes we’ll call this FixOurRouter.

text
line vty 0 4
 no access-class sl_def_acl in
line vty 5 15
 no access-class sl_def_acl in

In order to force the router to download the file, and apply the configuration changes, we simply modify a couple lines from our script. The SNMP MIBs for the OIDs 1.3.6.1.4.1.9.9.96.1.1.1.1.3 and 1.3.6.1.4.1.9.9.96.1.1.1.1.4 are ccCopySourceFileType and ccCopyDestFileType respectively. The integer values we can use for these are the following.

  1. networkFile
  2. iosFile (a file on flash)
  3. startupConfig
  4. runningConfig
  5. terminal

In our first script, we our copy source was set to 4, or runningConfig, and the destination was networkFile. In order to merge our configuration with the running-config we’re going to simply reverse these settings. You’ll also need to change the FILENAME variable to the new one with the configuration sniplet we just created.

bash
#!/bin/bash
STRING=private
IP=10.8.4.1
TFTP=10.0.1.200
FILENAME=FixOurRouter
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 6
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.111 i 1
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 1
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 4
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a $TFTP
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s $FILENAME
snmpset -c $STRING -v 1 $IP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1

Once we run this command the VTY ACL will be removed. And if you’re lucky, that was the only issue preventing you from connecting to the router.

Related Posts

Automation & Tools · 1 min read

Remote Configuration Tip

2011.04.18

I got asked a rather interested question the other day.

Security · 8 min read

Best Practices and Securing Cisco IOS

2011.09.06

Everyone has different views on hardening IOS, and while I do not claim to be an expert, these are the practices that I commonly use when bringing up a new device.

Comments

12 archived comments from Disqus 2011–2017
Rob Gartley
Great read, and it’s definitely going in the toolbox, but here’s a link to “Billy the Kid’s Cisco SNMP Tool” (Freeware). Everything you got there and more. It’s a bit old but so is SNMP. Could’ve saved you a bit of time. http://bit.ly/orz77J
subnetwork
Great tip! I’ve always known it was possible to do this, but had no idea where to start. Great job of presenting a full solution.
amyengineer
Nice post!! I am certain I will be referencing this in the future :)
Spyros K

Great tip! I’ll definitely have to bookmark that in case I need it :)

However, the acl you reference is the default quiet mode acl ( more info : http://www.cisco.com/en/US/docs/ios/sec_user_serv… ) . It won’t show up in the config, but if you have quiet mode configured and do a “show access-list” , you’ll be able to see it there.

I’ve heard of cases where the router was in quiet mode, somebody saved the config and after the next reload this acl got permanently applied to the vty lines as it was in the startup config. Not sure if that ever got “fixed” since the stories about it are quite old.

For what it’s worth, at least on the platforms I’ve tried it on, if you reference a non-existent acl under the vty lines, it will do absolutely nothing .

tom_m
Nice post.I think this is very helpful for all of us, thank you…..great job and good sharing…
simplesimon
Hi, nice post, I have been looking at doinf this today and like the bash script you have made. What if you needed to add/change the routers “ip tftp source-interface xx” ?
Tony
Unfortunately I wasn’t able to find a way to do that… I ended up having to add some static routes in my network to get to the P2P address on the device I was attempting to fix.
Keith Miller
Pardon my ignornance, I am a new network administrator but how did you run the bash file? Was this from a Windows platform or a Unix/Linux platform…
Tony
No problem Keith, this was from a Linux server, but it could’ve just as easily been from a Mac, or a Windows desktop running Cygwin.
Keith Miller
AH yes Cygwin… I keep hearing about it but I have no experience with it. Sounds like something I need to get a hold of and learn. Thanks Tony.
alex
Thanks
Hedbert

Hi,

I have been following this guide to reset a remote vty password and the tftp is failing I believe that its because the router needs a “ip tftp source-interface” in order to get into the correct vrf to get to my tftp server. Does anyone know how I would set the “ip tftp source-interface” using snmpset?