-I/usr/local/include/ucd-snmp -lsnmp -lcrypto 옵션을 붙여서 컴파일해야 한다.
snmptest 명령어을 이용하여 제대로 설치가 되었는지 테스트해 볼수 있다.
[root@note snmp]# snmptest 192.168.119.128 publicVariable: system.sysDescr.0Variable: system.sysName.0Variable: Received Get Response from 192.168.119.128requestid 0x456B696C errstat 0x0 errindex 0x0system.sysDescr.0 = Linux note.wmware.org 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686system.sysName.0 = note.wmware.orgVariable: [root@note snmp]#
snmpget 명령어는 명령어 이름에서 알수 있듯이 에이전트로부터 정보을 얻어 오는데 사용되는 명령어 있다. 인자값으로 MIB의 계층이름이나 OID 번호을 넣을수 있다. snmpget 명령어는 snmp get의 기능을 구현한 명령어이기 때문에 하위 계층의 정보는 가져 오지 않는다.
[root@note bin]# snmpget localhost public system.sysDescr.0system.sysDescr.0 = Linux note.wmware.org 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686[root@note bin]# snmpget localhost public 1.1.0 system.sysDescr.0 = Linux note.wmware.org 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686[root@note bin]# snmpget localhost public 1.2.0 system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.linux[root@note bin]# snmpget localhost public 1.3.0 system.sysUpTime.0 = Timeticks: (837696) 2:19:36.96[root@note bin]# snmpget localhost public 1.4.0 system.sysContact.0 = root@[root@note bin]# snmpget localhost public 1.5.0 system.sysName.0 = note.wmware.org[root@note bin]# snmpget localhost public 1.6.0 system.sysLocation.0 = Unknown[root@note bin]# snmpget localhost public 1.7.0 Error in packetReason: (noSuchName) There is no such variable name in this MIB.Failed object: system.sysServices.0[root@note bin]# snmpget localhost public 1.8.0 system.sysORLastChange.0 = Timeticks: (1) 0:00:00.01[root@note bin]# snmpget localhost public 1.9.0 Error in packetReason: (noSuchName) There is no such variable name in this MIB.Failed object: system.sysORTable.0[root@note bin]# snmpget localhost public 1.10.0 Error in packetReason: (noSuchName) There is no such variable name in this MIB.Failed object: system.10.0[root@note bin]#
4.2.3 snmpgetnext #
snmpgetnext 명령어는 snmp next의 기능을 구현한 명령어이다. 하지만 하위 계층의 정보을 모두 가져 오는것이 아니라 바로 다음 계층의 정보을 가져오게 된다. 결론적으로 1개의 정보을 가져오게 되는것이다. 예을 들어 system.sysDescr.0 에 대한 정보을 요청하면 하위 계층의 정보인 system.sysObjectID.0 의 정보을 가져 온다.
[root@note bin]# snmpgetnext localhost public 1.1.0 system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.linux
snmpwalk 명령어도 snmp next의 기능을 구현한 명령어로 하위 계층의 정보을 모두 가져 온다. -Of 옵션은 Full OID output -On 옵션은 OID number output 이다.
[root@note bin]# snmpwalk localhost public 1 system.sysDescr.0 = Linux note.wmware.org 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.linuxsystem.sysUpTime.0 = Timeticks: (47405) 0:07:54.05system.sysContact.0 = root@system.sysName.0 = note.wmware.orgsystem.sysLocation.0 = Unknownsystem.sysORLastChange.0 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORID.1 = OID: ifMIBsystem.sysORTable.sysOREntry.sysORID.2 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpMIBsystem.sysORTable.sysOREntry.sysORID.3 = OID: tcpMIBsystem.sysORTable.sysOREntry.sysORID.4 = OID: ipsystem.sysORTable.sysOREntry.sysORID.5 = OID: udpMIBsystem.sysORTable.sysOREntry.sysORID.6 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpVacmMIB.vacmMIBConformance.vacmMIBGroups.vacmBasicGroupsystem.sysORTable.sysOREntry.sysORID.7 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpFrameworkMIB.snmpFrameworkMIBConformance.snmpFrameworkMIBCompliances.snmpFrameworkMIBCompliancesystem.sysORTable.sysOREntry.sysORID.8 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpMPDMIB.snmpMPDMIBConformance.snmpMPDMIBCompliances.snmpMPDCompliancesystem.sysORTable.sysOREntry.sysORID.9 = OID: .iso.org.dod.internet.snmpV2.snmpModules.snmpUsmMIB.usmMIBConformance.usmMIBCompliances.usmMIBCompliancesystem.sysORTable.sysOREntry.sysORDescr.1 = The MIB module to describe generic objects for network interface sub-layerssystem.sysORTable.sysOREntry.sysORDescr.2 = The MIB module for SNMPv2 entitiessystem.sysORTable.sysOREntry.sysORDescr.3 = The MIB module for managing TCP implementationssystem.sysORTable.sysOREntry.sysORDescr.4 = The MIB module for managing IP and ICMP implementationssystem.sysORTable.sysOREntry.sysORDescr.5 = The MIB module for managing UDP implementationssystem.sysORTable.sysOREntry.sysORDescr.6 = View-based Access Control Model for SNMP.system.sysORTable.sysOREntry.sysORDescr.7 = The SNMP Management Architecture MIB.system.sysORTable.sysOREntry.sysORDescr.8 = The MIB for Message Processing and Dispatching.system.sysORTable.sysOREntry.sysORDescr.9 = The management information definitions for the SNMP User-based Security Model.system.sysORTable.sysOREntry.sysORUpTime.1 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.2 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.3 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.4 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.5 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.6 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.7 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.8 = Timeticks: (0) 0:00:00.00system.sysORTable.sysOREntry.sysORUpTime.9 = Timeticks: (0) 0:00:00.00[root@note snmp]# snmpwalk -Of localhost private memory .iso.org.dod.internet.private.enterprises.ucdavis.memory.memIndex.0 = 0.iso.org.dod.internet.private.enterprises.ucdavis.memory.memErrorName.0 = swap.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalSwap.0 = 264560.iso.org.dod.internet.private.enterprises.ucdavis.memory.memAvailSwap.0 = 261656.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalReal.0 = 191272.iso.org.dod.internet.private.enterprises.ucdavis.memory.memAvailReal.0 = 13140.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalFree.0 = 274796.iso.org.dod.internet.private.enterprises.ucdavis.memory.memMinimumSwap.0 = 16000.iso.org.dod.internet.private.enterprises.ucdavis.memory.memShared.0 = 0.iso.org.dod.internet.private.enterprises.ucdavis.memory.memBuffer.0 = 28148.iso.org.dod.internet.private.enterprises.ucdavis.memory.memCached.0 = 129248.iso.org.dod.internet.private.enterprises.ucdavis.memory.memSwapError.0 = 0.iso.org.dod.internet.private.enterprises.ucdavis.memory.memSwapErrorMsg.0 = [root@note snmp]# snmpwalk -On localhost private memory .1.3.6.1.4.1.2021.4.1.0 = 0.1.3.6.1.4.1.2021.4.2.0 = swap.1.3.6.1.4.1.2021.4.3.0 = 264560.1.3.6.1.4.1.2021.4.4.0 = 261656.1.3.6.1.4.1.2021.4.5.0 = 191272.1.3.6.1.4.1.2021.4.6.0 = 13132.1.3.6.1.4.1.2021.4.11.0 = 274788.1.3.6.1.4.1.2021.4.12.0 = 16000.1.3.6.1.4.1.2021.4.13.0 = 0.1.3.6.1.4.1.2021.4.14.0 = 28152.1.3.6.1.4.1.2021.4.15.0 = 129248.1.3.6.1.4.1.2021.4.100.0 = 0.1.3.6.1.4.1.2021.4.101.0 = [root@note snmp]#