linux下的SNMP配置tips
附上我的snmpd.conf
其中启用了V2c(V2c用community认证) 以及V3版本
##############snmpd.conf###############
com2sec local 192.168.23.128 rolo #限定rolo组只能来自192.168.23.128
com2sec local 192.168.23.1/24 ronet #不知为何ronet在本地不能用
createUser snmproot MD5 "auxtenwpc" DES auxtenwpc #V3的认证 snmproot为用户名 auxtenwpc为SN
group MyROGroup v2c local #MyROGroup不要更改这个名字
group MyROGroup usm local
group groupv3 usm root#这个貌似是废话
view all included .iso 80 #.iso同.1是三大主要分支之一
rwuser snmproot
access MyROGroup "" any noauth exact all none none #从第三个字段看是依次是 context sec.model sec.level match read write notif
access groupv3 "" any auth exact all all all
extend .1.3.6.1.4.1.2021.554 test@ /bin/bash /root/j.sh #j.sh随便写写就可以 主意应定要加个名字,如此处的test@,不然脚本会出错 还可以用exec 扩展2021这个分支是Enterprise的别和已有的几个分支重复此处的554可以乱取(不要太大 没研究过上限是多少);在用exec扩展的时候出现莫名其妙的错误 最好还是用extend关键字扩展
##############snmpd.conf###############
##############j.sh###############
echo "$PATH"
echo `pwd``uname`
##############j.sh###############
在本地运行snmpwalk -v 2c -c rolo 192.168.23.128 .1.3.6.1.4.1.2021.554 或者 snmpwalk -v 3 -u snmproot -A auxtenwpc -l authnopriv 192.168.23.128 .1.3.6.1.4.1.2021.554 都可以遍历红色部分的资料如下所示:
UCD-SNMP-MIB::ucdavis.554.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.554.2.1.2.5.116.101.115.116.64 = STRING: "/bin/bash"
UCD-SNMP-MIB::ucdavis.554.2.1.3.5.116.101.115.116.64 = STRING: "/root/j.sh"
UCD-SNMP-MIB::ucdavis.554.2.1.4.5.116.101.115.116.64 = ""
UCD-SNMP-MIB::ucdavis.554.2.1.5.5.116.101.115.116.64 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.554.2.1.6.5.116.101.115.116.64 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.554.2.1.7.5.116.101.115.116.64 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.554.2.1.20.5.116.101.115.116.64 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.554.2.1.21.5.116.101.115.116.64 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.554.3.1.1.5.116.101.115.116.64 = STRING: "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
UCD-SNMP-MIB::ucdavis.554.3.1.2.5.116.101.115.116.64 = STRING: "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
/Linux"
UCD-SNMP-MIB::ucdavis.554.3.1.3.5.116.101.115.116.64 = INTEGER: 2
UCD-SNMP-MIB::ucdavis.554.3.1.4.5.116.101.115.116.64 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.554.4.1.2.5.116.101.115.116.64.1 = STRING: "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
UCD-SNMP-MIB::ucdavis.554.4.1.2.5.116.101.115.116.64.2 = STRING: "/Linux"