snmpd on Red Hat/CentOS

This will be a running article on configuring and using snmpd on Red Hat/CentOS systems.

First make sure that the following packages are installed:

net-snmp-libs
net-snmp
net-snmp-utils
net-snmp-perl
php-snmp

The easiest way to get this working is to backup the /etc/snmp/snmpd.conf file that comes with the distribution and create a new, clean, one that has just the following line:

rocommunity     public

This will allow anyone and anything to query the service for read only. As we go on I’ll show how to lock it down more, but this will do for just getting acquainted with the protocol.

To enable the service do a /sbin/service snmpd start. To make sure it comes up on every reboot run /sbin/chkconfig snmpd on.

Test that things are working by querying snmp on the machine using snmpwalk.

snmpwalk -v 1 -c public myserver ifphysaddress

The command syntax is described in the man page, but basically it requires that you set the version (-v 1), a community string (-c public), the hostname (myserver) and indicate the place in the snmp object tree you want to query (ifphysaddress).

The response in this case would be a listing of all network interfaces and their MAC address. The last two lines are actually the virtual interfaces created by vmnet (VMWare Server). Something like this:

IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING: 0:13:12:d4:1g:29
IF-MIB::ifPhysAddress.3 = STRING:
IF-MIB::ifPhysAddress.4 = STRING: 0:50:25:c0:0:8
IF-MIB::ifPhysAddress.5 = STRING: 0:50:25:c0:0:1

For some distributions of net-snmp a slightly different syntax will work. In every case you could substitute the MIB number of an object for the friendly name given here.

A handy tool to have when working with snmp is a MIB browser of some kind. I use Aaron Hodgen’s GTK based mbrowse, which is available as an rpm package for Red Hat/CentOS from RPMForge.

mbrowse MIB Browser

Basically you scroll down the object tree to find what you’re looking for, highlight it and click “Walk” to view it’s value. Pretty simple, but also very useful when you’re trying to decide what objects you want to query using a script (Perl’s Net::SNMP, for example) or a monitoring application (e.g., Nagios).