133
Second, the leading dot is important. NET SNMP will attempt to attach a prefix to any OIDs not beginning with a dot. By default, the prefix is
1.3.6.1.2.1
, but you can change this by setting the environment variable PREFIX. In this example, we have specified the OID explicitly. Without the
leading dot, snmpget would have added the prefix to what we had, giving an OID that was too long. On the other hand, you could just use
1.1.0
without the leading dot and you would get the same results. Initially, using the prefix can be confusing, but it can save a lot of typing once you are used to
it. Of course, you can also use names rather than numbers, provided the appropriate MIB is available.
This is shown in the next two examples:
bsd4 snmpget 172.16.1.5 public iso.org.dod.internet.mgmt.mib- 2.system.sysDescr.0
system.sysDescr.0 = APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9
605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0 bsd4 snmpget 172.16.1.5 public system.sysDescr.0
system.sysDescr.0 = APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod: AP9
605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0
In the first case, the full path was given, and in the second the prefix was used. Dont forget the trailing
. Numbers and names can be mixed:
bsd4 snmpget 172.16.1.5 public .1.3.6.internet.2.1.system.1.0 system.sysDescr.0 = APC Embedded PowerNet SNMP Agent SW v2.2, HW vB2, Mod:
AP9 605, Mfg 081096, SN: WA9632270847, Agent Loader v1.0
Frankly, I cant see much reason for doing this. Also, if the MIB is known, you can do a random-access lookup for unique node names:
bsd4 snmpget 172.16.1.5 public upsBasicIdentModel.0 enterprises.apc.products.hardware.ups.upsIdent.upsBasicIdent.upsBasicIdentModel.
0 = APC Smart-UPS 700
In this example, only the final identifier in the OID,
upsBasicIdentMode.0
, is given, and the MIB is searched to construct the full OID. This can be particularly helpful if you want to query several
objects with a single snmpget. You can also use multiple OIDs in the same snmpget command to retrieve the values of several objects.
7.2.1.2 Configuration and options
Before we look further at the NET SNMP commands, lets discuss configuration and options. For the most part, these tools share the same configuration files and options. A few exceptions will be noted
when appropriate. The general configuration file is snmp.conf and is typically in the usrlocalsharesnmp, usrlocallibsnmp, or HOME.snmp directory. This search path can be
overridden by setting the SNMPCONFPATH environment variable. Further documentation can be found in the snmp.conf Unix manpage. This manpage also describes environment variables.
One particular concern in configuring the software is the proper installation of MIBs. As noted earlier, use of the name form of OIDs works only if the appropriate MIB
[1]
is loaded. Devices may have more than one MIB associated with them. In the examples just presented, we have been interacting with an
134
SNMP-controlled uninterruptible power supply UPS manufactured by APC Corp. With this device, we can use the standard default MIB-II defined in RFC 1213. This standard MIB defines objects used
by most devices. If you have correctly installed the software, this MIB should be readily available. There are two additional MIBs that may be installed for this particular device. The first is the IETF
MIB, which defines a generic UPS. This is the UPS-MIB defined by RFC 1628. The third MIB, PowerNet-MIB, contains APC Corp.s custom extensions. These last two MIBs came on a diskette
with the SNMP adapter for this particular UPS.
[1]
When a MIB is loaded, it becomes part of the MIB. Dont say I didnt warn you.
To install these MIBs, the files are first copied to the appropriate directory, usrlocalsharesnmp in this case. You may also want to rename them so that all your MIB files have consistent names. Next,
the environment variable MIBS is set so the MIBs will be loaded. This can be a colon-delimited list of individual MIB names, but setting MIBS to
ALL
is usually simpler. On a Windows computer, use the command:
C:\usr\binset MIBS=ALL
On a Unix system using the Bash shell, you would use:
export MIBS=ALL
For the C-shell, use:
setenv MIBS ALL
Of course, this may vary depending on the shell you use. Alternately, you can use the environment variable MIBFILES to specify filenames. There is also a
command-line option with most of these utilities, -m, to load specific MIBs. If the MIBs are not installed correctly, you will not be able to use names from the MIB, but you can still access objects by
their numerical OIDs.
The NET SNMP commands use the same basic syntax and command-line options. For example, the earlier discussion on OID usage applies to each command. This is described in the variables manpage.
The manpages for the individual commands are a little sparse. This is because the descriptions of the options have been collected together on the snmpcmd manpage. Options applicable to a specific
command can be displayed by using the -h option.
Lets return to snmpget and look at some of the available options. The -O options control how output is formatted. The default is to print the text form of the OID:
bsd4 snmpget 172.16.1.5 public .1.3.6.1.4.1.318.1.1.1.1.1.1.0 enterprises.apc.products.hardware.ups.upsIdent.upsBasicIdent.upsBasicIdentModel.
0 = APC Smart-UPS 700
-On forces the OID to be printed numerically:
bsd4 snmpget -On 172.16.1.5 public .1.3.6.1.4.1.318.1.1.1.1.1.1.0 .1.3.6.1.4.1.318.1.1.1.1.1.1.0 = APC Smart-UPS 700
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