How to install and use snmpwalk

How to install and use snmpwalk

Snmpwalk is a great tool for Linux boxes. You can easily list all OIDs a SNMP host has to offer then filter the results to your needs and find OIDs to import into tools like Cacti. Snmpwalk is in most linux repos so its easy to install e.g:

Fedora/Centos: yum install net-snmp-utils
Ubuntu: apt-get install snmp

The syntax to use snmpwalk is also pretty simple:

m00nie@linuxBox:~$snmpwalk --help
USAGE: snmpwalk [OPTIONS] AGENT [OID]

Version:  5.4.2.1
Web:      http://www.net-snmp.org/
Email:    net-snmp-coders@lists.sourceforge.net</code>

OPTIONS:
-h, --help            display this help message
-H                    display configuration file directives understood
-v 1|2c|3             specifies SNMP version to use
-V, --version         display package version number SNMP Version 1 or 2c specific
-c COMMUNITY          set the community string SNMP Version 3 specific
-a PROTOCOL           set authentication protocol (MD5|SHA)
-A PASSPHRASE         set authentication protocol pass phrase
-e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
-E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
-l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
-n CONTEXT            set context name (e.g. bridge1)
-u USER-NAME          set security name (e.g. bert)
-x PROTOCOL           set privacy protocol (DES|AES)
-X PASSPHRASE         set privacy protocol pass phrase
-Z BOOTS,TIME         set destination engine boots/time General communication options
-r RETRIES            set the number of retries
-t TIMEOUT            set the request timeout (in seconds)
Debugging
-d                    dump input/output packets in hexadecimal
-D TOKEN[,...]        turn on debugging output for the specified TOKENs (ALL gives extremely verbose debugging output)

A copy of the man page can be found here.
So a simple example of listing all OIDs on a host with an IP of 10.20.30.1 using snmp version two and a community string of mysecretsnmp would be:

m00nie@linuxBox:~$ snmpwalk -v 2c -c mysecretsnmp 10.20.30.1
SNMPv2-MIB::sysDescr.0 = STRING: Linux somevpn.m00nie.com 2.4.31 #2 SMP Fri Aug 22 23:02:05 PDT 2008 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-TC::linux
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (22119) 0:03:41.19
SNMPv2-MIB::sysContact.0 = STRING: m00nie Networks
SNMPv2-MIB::sysName.0 = STRING: F5.m00nie.com
SNMPv2-MIB::sysLocation.0 = STRING: m00nieland
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
<SNIP>
NOTIFICATION-LOG-MIB::nlmLogTime."default".1 = Timeticks: (12) 0:00:00.12
NOTIFICATION-LOG-MIB::nlmLogDateAndTime."default".1 = STRING: 2010-8-23,13:50:31.0,+1:0
m00nie@linuxBox:~$

Now to only view one OID value we can append the OID SNMPv2-MIB::sysContact.0

m00nie@linuxBox:~$ snmpwalk -v 2c -c mysecretsnmp 10.20.30.1 SNMPv2-MIB::sysContact.0
SNMPv2-MIB::sysContact.0 = STRING: m00nie Networks
m00nie@linuxBox:~$

To display the numerical OID for each snmp value use the "-O n" switch. Useful for Cacti as it only uses the numerical OID ;)

m00nie@linuxBox:~$ snmpwalk -v 2c -O n -c mysecretsnmp 10.20.30.1 SNMPv2-MIB::sysContact.0
.1.3.6.1.2.1.1.4.0 = STRING: m00nie Networks
m00nie@linuxBox:~$

You can also use the numerical OID to refine the output.

m00nie@linuxBox:~$ snmpwalk -v 2c -O n -c mysecretsnmp 10.20.30.1 .1.3.6.1.2.1.1.4.0
.1.3.6.1.2.1.1.4.0 = STRING: m00nie Networks
m00nie@linuxBox:~$

Now if your linux box is also running Cacti or similar you have proven SNMP connectivity so importing like this is easy, allowing the graphing of the value.

m00nie :)