如何通过SNMP协议保存思科路由器配置文件

Everyone knows there are software to get the configuration using SNMP; but how can you copy the configuration if you don’t have any tool?

Let me explain what is SNMP before show you how to implement it.

Simple Network Management Protocol (SNMP) is an “Internet-standard protocol for managing devices on IP networks”. Devices that typically support SNMP include routers, switches, servers, workstations, printers, modem racks, and more. It is used mostly innetwork management systems to monitor network-attached devices for conditions that warrant administrative attention. SNMP uses an extensible design, where the available information is defined by management information bases (MIBs). MIBs describe the structure of the management data of a device subsystem; they use a hierarchical namespace containing object identifiers (OID). Each OID identifies a variable that can be read or set via SNMP.

In this tutorial, I will use the

OK, let’s start :)

First of all, check if your PC has the SNMP suite; if not, install the net-snmp software (http://net-snmp.sourceforge.net/).

So, to retrieve the configuration, run these commands:

snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.2.336 i 1
snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4
snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1
snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.5.336 a [ip-tftp-server]
snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.6.336 s [file-name]
snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.14.336 i 1

where:

  • snmp-community-string is the community key of your cisco router.
  • ip-device is the ip address of your Cisco device.
  • ip-tftp-server is the ip address of your tftp server.
  • file-name is the name where the running configuration will be saved.

Remember: The command syntax are the same on linux or windows devices.

Example #1:
Suppose you have a Cisco Router (192.168.1.1) with the “c1sc0zine” community string, a tftp server with 192.168.1.100 ip address and you want to save the running configuration to the tftp-server (in the ciscozine.txt file).

 

How-to-save-the-running-configuration-using-SNMP

The client sends the “snmp set” commands to the router, then the router sends the running configuration to the tftp server using the tftp protocol.

Below the command list:

snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.2.336 i 1
snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4
snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1
snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.5.336 a 192.168.1.100
snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.6.336 s ciscozine.txt
snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.14.336 i 1

But what is the meaning of the last part of each command? See you below an explanation:

1.3.6.1.4.1.9.9.96.1.1.1.1.2.336 i 1

ccCopyProtocol: The protocol file transfer protocol that should be used to copy the configuration file over the network. If the config file transfer is to occur locally on the SNMP agent, the method of transfer is left up to the implementation, and is not restricted to the protocols below. The object can be:

  1. tftp
  2. ftp
  3. rcp
  4. scp
  5. sftp

 

1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4

ccCopySourceFileType: Specifies the type of file to copy from. The object can be:

  1. networkFile
  2. iosFile
  3. startupConfig
  4. runningConfig
  5. terminal
  6. fabricStartupConfig

 

1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1

ccCopyDestFileType: specifies the type of file to copy to. The object can be:

  1. networkFile
  2. iosFile
  3. startupConfig
  4. runningConfig
  5. terminal
  6. fabricStartupConfig

 

1.3.6.1.4.1.9.9.96.1.1.1.1.5.336 a 192.168.1.100

ccCopyServerAddress: The IP address of the TFTP server to copy the configuration file. In this case the tftp server is 192.168.1.100.

 

snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.6.336 s ciscozine.txt

ccCopyFileName: The file name (including the path, if applicable) of the file.

 

1.3.6.1.4.1.9.9.96.1.1.1.1.14.336 i 1

ccCopyEntryRowStatus: The status of this table entry. Once the entry status is set to active, the associated entry cannot be modified until the request completes (ccCopyState transitions to ‘successful’ or ‘failed’ state). The object can be:

  1. active
  2. notInService
  3. notReady
  4. createAndGo
  5. createAndWait
  6. destroy

Note: When you run this command, the router will send the running configuration to the ftp-server!

 

Remember: The object types can be:

  • i: INTEGER
  • u: unsigned INTEGER
  • t: TIMETICKS
  • a: IPADDRESS
  • o: OBJID
  • s: STRING
  • x: HEX STRING
  • d: DECIMAL STRING
  • b: BITS
  • U: unsigned int64
  • I: signed int64
  • F: float
  • D: double

 

Example #2:
What can you do if you are not able to install/use the net-snmp suite on your pc? It’s simple! Use your router!

 

How-to-save-the-running-configuration-using-SNMP-2

Not everyone knows that the IOS has an embedded hidden commands for snmp operation. In fact, if you want to save the startup configuration to the tftp server, run these commands on your router:

snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.2.333 integer 1
snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.3.333 integer 3
snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.4.333 integer 1
snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.5.333 ip-address 192.168.1.100
snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.6.333 string ciscozine.txt
snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.14.333 integer 1

as you notice, the last value of the second line is “3” and not “4”; this because I want save the startup configuration, not the running configuration!

The output will be:

Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.2.333 integer 1
SNMP Response: reqid 8, errstat 0, erridx 0 
 ccCopyTable.1.2.333 = 1
Ciscozine-test#
Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.3.333 integer 3
SNMP Response: reqid 9, errstat 0, erridx 0 
 ccCopyTable.1.3.333 = 3
Ciscozine-test#
Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.4.333 integer 1
SNMP Response: reqid 10, errstat 0, erridx 0 
 ccCopyTable.1.4.333 = 1
Ciscozine-test#
Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.5.333 ip-address 192.168.1.100
SNMP Response: reqid 11, errstat 0, erridx 0 
 ccCopyTable.1.5.333 = 192.168.1.100
Ciscozine-test#
Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.6.333 string ciscozine.txt
SNMP Response: reqid 12, errstat 0, erridx 0 
 ccCopyTable.1.6.333 = ciscozine.txt
Ciscozine-test#
Ciscozine-test#snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.14.333 integer 1
SNMP Response: reqid 13, errstat 0, erridx 0 
 ccCopyTable.1.14.333 = 1
Ciscozine-test#

… and your tftp server will receive the startup configuration!

Note: What is the last OID element (in these two examples the number “333”)? It’s arandom number! Each time you copy to or from a device using SNMP, choose a random number. This number creates a row instance. It must be the same everywhere in your command. Once you use a specific number, it can not be used again before it times out.The timeout is five minutes. If you use the same number within the five minutes, you get an error (SNMP: Inconsistent value.)

References:



Summary
How to save configurations using SNMP
Article Name
How to save configurations using SNMP
Description
Generally, the SNMP protocol is used to receive bandwith/error interface values, but not everyone know that it is possibile to save Cisco configuration using the ciscoConfigCopyMIB MIB.
Author
Fabio Semperboni
How to save configurations using SNMP
  • salman

    what if i don’t have dedicated tftp server in my LAN and i have installed cisco tftp server software on my personal laptop
    so it’ll work????
    and if i put all these commands then will i get configuration automatically whenever there’ll be a change in configuration of that router????
    kindly help me to clear my confusion!!!

  • Hi,
    it is not mandatory that the tftp server is in the same vlan.
    For the second question, no the command save the configuration only one time; if you change the configuration you need run again the command.

  • Gian Matteo Esposito

    Simple and great. You are one of my “numbers one” !

    Last example (self snmp set) is very cute… and certainly the best way to complicate your life instead of using the trivial “copy start tftp” ;)

  • Thanks for the congrats :)

  • roseliopi

    wonderful, help me a lot, for a newer.

  • pughaz

    Can we schedule this every day or weekly …
    As a auto backup

  • Pingback: Send Cisco commands via SNMP | CiscoZine()

  • DEDE

    Thank you so much Fabio Semperboni it works perfectly

  • unixrab

    Fabio… how would I reverse this and send the running config TO the router after I’ve made some changes FROM the tftpserver? Thanks!

  • Mijk Eielts

    copy tftp: run ?

  • It depends by the protocol you would use to change configuration.


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值