Sunday, June 13, 2021

CISCO XR copy configuration to TFTP by SNMP

 遇到一个客户有这样的需求,想使用SNMP的方式去copy设备的配置到TFTP server。查了点资料发现真存在这种方式,虽然感觉这种功能很鸡肋,但还是记录以下以备查询。

SNMPWALK

Snmpwalk是一个很好用的小工具,平常查OID值的时候经常会遇到,Centos的话直接用yum进行安装就行了。

yum -y install net-snmp net-snmp-utils
snmpwalk -v 2c -c cisco 10.75.49.13 1.3.6.1.2.1.1.3.0

配置CISCO设备

RP/0/RSP0/CPU0:CORE4-ASR9010-A#show run snmp-server 
snmp-server community public RW

COPY配置

* Create an Entry and Wait(777 is a random session number):
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 5
* Set Copy protocol to tftp
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.2.777 i 1
* Set copy to tftp server
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.3.777 i 4
* Set copy from config  
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.4.777 i 1
* Set tftp server address
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.5.777 a 10.75.49.254
* Set destination file name
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.6.777 s xuxingtest
* Activate the entry 
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 1
* Once successful, destroy the entry
snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 6

EXAMPLE

[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 5
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.14.777 = INTEGER: 5
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.2.777 i 1
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.2.777 = INTEGER: 1
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.3.777 i 4
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.3.777 = INTEGER: 4
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.4.777 i 1
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.4.777 = INTEGER: 1
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.5.777 a 10.75.49.254
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.5.777 = IpAddress: 10.75.49.254
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.6.777 s xuxingtest
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.6.777 = STRING: "xuxingtest"
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 1
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.14.777 = INTEGER: 1
[root@xuxing ~]# snmpset -v2c -c public 10.75.49.9 .1.3.6.1.4.1.9.9.96.1.1.1.1.14.777 i 6
SNMPv2-SMI::enterprises.9.9.96.1.1.1.1.14.777 = INTEGER: 6

VERIFY:

login device you will see below syslog:

RP/0/RSP0/CPU0:Dec 10 13:39:34.876 : syslog_dev[95]: mibd_infra[338] PID-13783439: Building configuration. 
RP/0/RSP0/CPU0:Dec 10 13:39:34.876 : syslog_dev[95]: mibd_infra[338] PID-13783439:  
RP/0/RSP0/CPU0:Dec 10 13:39:34.876 : syslog_dev[95]: mibd_infra[338] PID-13783439: 2325 lines built in 1 second 
RP/0/RSP0/CPU0:Dec 10 13:39:34.876 : syslog_dev[95]: mibd_infra[338] PID-13783439: [OK
           

This Blog from Xuxing's Blog. Link: http://imxing.cn/?p=118

No comments:

Post a Comment