135
Sometimes the value of an object will be a cryptic numerical code. By default, a description will be printed. For example:
bsd4 snmpget 172.16.1.5 public ip.ipForwarding.0 ip.ipForwarding.0 = not-forwarding2
Here, the actual value of the object is
2
. This description can be suppressed with the -Oe option:
bsd4 snmpget -Oe 172.16.1.5 public ip.ipForwarding.0 ip.ipForwarding.0 = 2
This could be useful in eliminating any confusion about the actual stored value, particularly if you are going to use the value subsequently with a SET command.
Use the -Os, -OS, and -Of commands to control the amount of information included in the OID. The - Os option displays the final identifier only:
bsd4 snmpget -Os 172.16.1.5 public enterprises.318.1.1.1.1.1.1.0 upsBasicIdentModel.0 = APC Smart-UPS 700
The -OS option is quite similar to -Os except that the name of the MIB is placed before the identifier:
sd4 snmpget -OS 172.16.1.5 public enterprises.318.1.1.1.1.1.1.0 PowerNet-MIB::upsBasicIdentModel.0 = APC Smart-UPS 700
-Of forces the display of the full OID:
bsd4 snmpget -Of 172.16.1.5 public enterprises.318.1.1.1.1.1.1.0 .iso.org.dod.internet.private.enterprises.apc.products.hardware.ups.upsIdent.
upsBasicIdent.upsBasicIdentModel.0 = APC Smart-UPS 700
This leaves no question about what you are looking at. There are a number of additional options. The -V option will return the programs version. The version
of SNMP used can be set with the -v option, either
1
,
2c
, or
3
. The -d option can be used to dump all SNMP packets. You can set the number of retries and timeouts with the -r and -t options. These few
options just scratch the surface. The syntax for many of these options has changed recently, so be sure to consult the snmpcmd manpage for more options and details for the version you use.
7.2.1.3 snmpgetnext, snmpwalk, and snmptable
Sometimes you will want to retrieve several related values that are stored together within the agent. Several commands facilitate this sort of retrieval. The snmpgetnext command is very similar to the
snmpget command. But while snmpget returns the value of the specified OID, snmpgetnext returns the value of the next object in the MIB tree:
bsd4 snmpget -Os 172.16.1.5 public sysDescr.0 sysDescr.0 = APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9605,
Mfg 081096, SN: WA9632270847, Agent Loader v1.0
bsd4 snmpgetnext -Os 172.16.1.5 public sysDescr.0 sysObjectID.0 = OID: smartUPS700
bsd4 snmpgetnext -Os 172.16.1.5 public sysObjectID.0 sysUpTime.0 = Timeticks: 77951667 9 days, 0:31:56.67
136
bsd4 snmpgetnext -Os 172.16.1.5 public sysUpTime.0 sysContact.0 = Sloan
As you can see from this example, snmpgetnext can be used to walk through a sequence of values. Incidentally, this is one of the few cases in which it is OK to omit the trailing
. This command can be particularly helpful if you dont know the next identifier.
If you want all or most of the values of adjacent objects, the snmpwalk command can be used to retrieve a subtree. For example:
bsd4 snmpwalk 172.16.1.5 public system system.sysDescr.0 = APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod:
AP9605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0 system.sysObjectID.0 = OID:
enterprises.apc.products.system.smartUPS.smartUPS700 system.sysUpTime.0 = Timeticks: 78093618 9 days, 0:55:36.18
system.sysContact.0 = Sloan system.sysName.0 = Equipment Rack APC
system.sysLocation.0 = Network Laboratory system.sysServices.0 = 72
Be prepared to be overwhelmed if you dont select a small subtree. You probably wouldnt want to walk the mib-2 or enterprises subtree:
bsd4 snmpwalk 172.16.2.1 public enterprises | wc 3320 10962 121987
In this example, the enterprises subtree is 3320 lines long. Nonetheless, even with large subtrees this can be helpful to get a quick idea of what is out there. For example, you might pipe output from a
subtree you arent familiar with to head or more so you can skim it.
Some objects are stored as tables. It can be painful to work with these tables one item at a time, and once you have them, they can be almost unreadable. snmptable is designed to address this need. Here
is an example of a small route table from a Cisco 3620 router:
bsd4 snmptable -Cb -Cw 80 172.16.2.1 public ipRouteTable SNMP table: ip.ipRouteTable
Dest IfIndex Metric1 Metric2 Metric3 Metric4 NextHop Type 0.0.0.0 0 0 -1 -1 -1 205.153.60.2 indirect
172.16.1.0 2 0 -1 -1 -1 172.16.1.1 direct 172.16.2.0 3 0 -1 -1 -1 172.16.2.1 direct
172.16.3.0 4 0 -1 -1 -1 172.16.3.1 direct 205.153.60.0 1 0 -1 -1 -1 205.153.60.250 direct
205.153.61.0 0 0 -1 -1 -1 205.153.60.1 indirect 205.153.62.0 0 0 -1 -1 -1 205.153.60.1 indirect
205.153.63.0 0 0 -1 -1 -1 205.153.60.1 indirect SNMP table ip.ipRouteTable, part 2
Proto Age Mask Metric5 Info local 33 0.0.0.0 -1 .ccitt.nullOID
local 0 255.255.255.0 -1 .ccitt.nullOID local 0 255.255.255.0 -1 .ccitt.nullOID
local 0 255.255.255.0 -1 .ccitt.nullOID local 0 255.255.255.0 -1 .ccitt.nullOID
local 33 255.255.255.0 -1 .ccitt.nullOID local 33 255.255.255.0 -1 .ccitt.nullOID
137
local 33 255.255.255.0 -1 .ccitt.nullOID
Even with snmptable, it can be a little tricky to get readable output. In this case, I have used two options to help. -Cb specifies a brief header. -Cw 80 defines a maximum column width of 80
characters, resulting in a multipart table. You can also specify the column delimiter with the -Cf option, and you can suppress headers altogether with the -CH option. There are also a snmpbulkget
and a snmpbulkwalk if you are using SNMPv2.
7.2.1.4 snmpset