Dealing with SNMP on Linux


Every time I need to work with Linux SNMP utilities, I have to re-learn some commands. This post summarize useful SNMP commnads for anyone who need a reference guide.

Common options

Usually I need to build a custom and trusted MIB repository. Every SNMP utility can take the following flags:

  • -M takes one or more directory where look for MIB file.
  • -m selectively load MIB files from the above directories. I usually use ALL.

SNMP Translate

Dealing with MIB files can be a pain. Sometimes is faster and simpler to use the numeric OIDs. But how we can find numeric OID from alphabetic ones and back?

Find mathing MIB files given a regex:

$ snmptranslate -m ALL -M mibs -TB sysName

Print the numeric OID given an alphabetic ones:

$ snmptranslate -m ALL -M $HOME/.snmp/mibs -On SNMPv2-MIB::sysName

Print the alphabetic OID given a numeric ones:

$ snmptranslate -m ALL -M $HOME/.snmp/mibs .

Print only last symbolic element of an OID (numeric or alphabetic):

$ snmptranslate -m ALL -M $HOME/.snmp/mibs -Os .

Print full alphabetic OID given a numeric ones:

$ snmptranslate -m ALL -M $HOME/.snmp/mibs -Of .

SNMP Get and Walk

Getting a single SNMP entry:

$ snmpget -m ALL -M $HOME/.snmp/mibs -v3 -l authNoPriv -u username -a SHA -A password sysName
SNMPv2-MIB::sysName = No Such Instance currently exists at this OID

The snmpget command does not “walk”, so the exact OID must be given:

$ snmpget -m ALL -M $HOME/.snmp/mibs -v3 -l authNoPriv -u username -a SHA -A password sysName.0
SNMPv2-MIB::sysName.0 = STRING:

Because of that, usually snmpwalk is preferred:

$ snmpwalk -m ALL -M $HOME/.snmp/mibs -v3 -l authNoPriv -u username -a SHA -A password sysName
SNMPv2-MIB::sysName.0 = STRING:

Get a table via SNMP

Some SNMP entry can be retrieved individually or aggregated (in a table): those attributes usually contains Table inside the alphabetic OID. Let’s retrieve, for example, ifTable:

$ snmptable -m ALL -M $HOME/.snmp/mibs -v3 -l authNoPriv -u username -a SHA -A password -Cf , ifTable
SNMP table: IF-MIB::ifTable


The above example will delimitate columns using a ,, useful to generate a CSV compatible output.

A large screen readable output can be the following:

$ snmptable -m ALL -M $HOME/.snmp/mibs -v3 -l authNoPriv -u username -a SHA -A password -Cc 10 ifTable
SNMP table: IF-MIB::ifTable

   ifIndex   ifDescr    ifType     ifMtu   ifSpeed ifPhysAdd ifAdminSt ifOperSta ifLastCha ifInOctet ifInUcast ifInNUcas ifInDisca ifInError ifInUnkno ifOutOcte ifOutUcas ifOutNUca ifOutDisc ifOutErro ifOutQLen ifSpecifi
         1 Ethernet0 ethernetC      1500  10000000 0:2:16:cd        up        up 0:13:59:4 193354931     81408  19173500       114       102   7143018 129757359   1081161    186811         0        48         0   ccitt.0
         2     Null0     other      1500 429496729                  up        up 0:0:00:00         0         0         0         0         0         0         0         0         0         0         0         0   ccitt.0


Posted on 29 Mar 2017.
  • Gmail icon
  • Twitter icon
  • Facebook icon
  • LinkedIN icon
  • Google+ icon