如何通过SNMP协议保存思科路由器配置文件
来源:互联网 发布:凯文史派西出柜 知乎 编辑:程序博客网 时间:2024/05/16 14:27
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 1snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4snmpset -c [snmp-community-string] -v 2c [ip-device] 1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1snmpset -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).
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 1snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.3.336 i 4snmpset -c c1sc0zine -v 2c 192.168.1.1 1.3.6.1.4.1.9.9.96.1.1.1.1.4.336 i 1snmpset -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.100snmpset -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.txtsnmpset -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:
- tftp
- ftp
- rcp
- scp
- 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:
- networkFile
- iosFile
- startupConfig
- runningConfig
- terminal
- 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:
- networkFile
- iosFile
- startupConfig
- runningConfig
- terminal
- 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:
- active
- notInService
- notReady
- createAndGo
- createAndWait
- 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!
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 1snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.3.333 integer 3snmp set v2c 192.168.1.1 c1sc0zine oid 1.3.6.1.4.1.9.9.96.1.1.1.1.4.333 integer 1snmp 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.100snmp 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.txtsnmp 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 1SNMP Response: reqid 8, errstat 0, erridx 0 ccCopyTable.1.2.333 = 1Ciscozine-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 3SNMP Response: reqid 9, errstat 0, erridx 0 ccCopyTable.1.3.333 = 3Ciscozine-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 1SNMP Response: reqid 10, errstat 0, erridx 0 ccCopyTable.1.4.333 = 1Ciscozine-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.100SNMP Response: reqid 11, errstat 0, erridx 0 ccCopyTable.1.5.333 = 192.168.1.100Ciscozine-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.txtSNMP Response: reqid 12, errstat 0, erridx 0 ccCopyTable.1.6.333 = ciscozine.txtCiscozine-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 1SNMP Response: reqid 13, errstat 0, erridx 0 ccCopyTable.1.14.333 = 1Ciscozine-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:
- http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol
- http://tools.cisco.com/Support/SNMP/do/BrowseOID.do?local=en
- 如何通过SNMP协议保存思科路由器配置文件
- 利用SNMP向思科路由器发送命令
- 利用SNMP攻击思科等交换机路由器等设备
- 利用SNMP攻击思科等交换机路由器等设备
- 思科路由器RIP协议v1实验
- Centos6.5编译安装zabbix2.2通过snmp协议监控路由器
- zabbix基于SNMP 协议监控路由器
- zabbix基于SNMP 协议监控路由器
- 如何进行思科路由器的安全配置
- 如何升级思科路由器的rommon
- 思科路由器防火墙如何配置的方法
- 思科cisco路由器动态路由协议配置方法
- 为CISCO路由器配置使用简单网络管理协议SNMP
- 路由器协议如何进行选择
- 思科 800 系列路由器
- 思科 1800 系列路由器
- 思科 2600 系列路由器
- 思科 3200 系列路由器
- 如何解决jdbc中出现的java.io.NotSerializableException
- Python 列表解析
- 程序猿的屌丝经历(二)
- 原生javascript实现ajax异步请求
- Combination Sum
- 如何通过SNMP协议保存思科路由器配置文件
- 查看部门里工资大于平均水平的员工信息,并按部门分组
- c印记(十三):表驱动编程——优美的逻辑优化者
- 深度学习笔记(三)
- java集合lis,set,map
- yuv数据格式介绍与rgb的转换,图像文件的封装
- 双向bfs——洛谷P1032 字串变换
- Python学习之matplotlib 绘制折线图详解
- node入门(三)-- mysql
Pingback: Send Cisco commands via SNMP | CiscoZine()