知乎專欄 | 多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者” |
目錄
search package
netkiller@neo:~$ apt-cache search snmp libsnmp-base - NET SNMP (Simple Network Management Protocol) MIBs and Docs libsnmp-perl - NET SNMP (Simple Network Management Protocol) Perl5 Support libsnmp-session-perl - Perl support for accessing SNMP-aware devices libsnmp9 - NET SNMP (Simple Network Management Protocol) Library libsnmp9-dev - NET SNMP (Simple Network Management Protocol) Development Files snmp - NET SNMP (Simple Network Management Protocol) Apps snmpd - NET SNMP (Simple Network Management Protocol) Agents php5-snmp - SNMP module for php5 tcpdump - A powerful tool for network monitoring and data acquisition
安裝
netkiller@neo:~$ sudo apt-get install snmp snmpd
配置 /etc/snmp/snmpd.conf
配置agentAddress
agentAddress udp:172.16.1.3:161
# sec.name source community com2sec paranoid default chen # incl/excl subtree mask view all included .1 80 view system included .iso.org.dod.internet.mgmt.mib-2.system view system included .iso.org.dod.internet.mgmt.mib-2.host view system included .iso.org.dod.internet.mgmt.mib-2.interfaces
.iso.org.dod.internet.mgmt.mib-2.host 可以使用命令 snmptranslate -Onf -IR hrStorageDescr得到
參考:http://www.mkssoftware.com/docs/man1/snmptranslate.1.asp
neo@debian:~$ sudo /etc/init.d/snmpd stop Stopping network management services: snmpd snmptrapd. neo@debian:~$ sudo net-snmp-config --create-snmpv3-user -ro -a "netadminpassword" netadmin adding the following line to /var/lib/snmp/snmpd.conf: createUser netadmin MD5 "netadminpassword" DES adding the following line to /usr/share/snmp/snmpd.conf: rouser netadmin neo@debian:~$ sudo /etc/init.d/snmpd start Starting network management services: snmpd.
test
neo@debian:~$ snmpget -v 3 -u netadmin -l authNoPriv -a MD5 -A <passwd> 127.0.0.1 sysUpTime.0 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (6342) 0:01:03.42
With a different password this fails:
neo@debian:~$ snmpget -v 3 -u netadmin -l authNoPriv -a MD5 -A nopasswd 127.0.0.1 sysUpTime.0 snmpget: Authentication failure (incorrect password, community or key) (Sub-id not found: (top) -> sysUpTime)
Note that this can be stuck in a snmp.conf file in ~/.snmp:
neo@debian:~$ mkdir ~/.snmp neo@debian:~$ vim ~/.snmp/snmp.conf defSecurityName netadmin defContext "" defAuthType MD5 defSecurityLevel authNoPriv defAuthPassphrase <netadminpassword> defVersion 3
test
neo@debian:~$ snmpget 127.0.0.1 sysUpTime.0 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (39471) 0:06:34.71
yum install net-snmp -y cp /etc/snmp/snmpd.conf{,.original} vim /etc/snmp/snmpd.conf <<VIM > /dev/null 2>&1 :62,62s/systemview/all/ :85,85s/^#// :162,162s/syslocation Unknown/syslocation Neo/ :163,163s/syscontact Root <root@localhost>/syscontact Neo <netkiller@msn.com>/ :wq VIM service snmpd start chkconfig snmpd on