Linux HOWTOs

About | Home | Search

HOWTO: net-snmp
Description: Simple Network Management Protocol library and tools
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything

# Net-SNMP 5.7.3
# ==============
# Prerequisites:
# procps
# Perl (unless --disable-embedded-perl and --without-perl-modules are passed)
# OpenSSL
# CUPS' lpstat (or lpr, lpr-ng, ...)
# Python (for the bindings in ./python/)
# MySQL (for MySQL trap logging)

# Get it
test -f installed/net-snmp-5.7.3.tar.gz &&
 mv installed/net-snmp-5.7.3.tar.gz .
test ! -f net-snmp-5.7.3.tar.gz &&

# Verify tarball w/ sha1sum:
# (this also came from my gpg-verified tarball)
echo "97dc25077257680815de44e34128d365c76bd839  net-snmp-5.7.3.tar.gz" \
| sha1sum -c

# Verify tarball w/ sha256sum:
# (this came from my gpg-verified tarball)
echo "12ef89613c7707dc96d13335f153c1921efc9d61d3708ef09f3fc4a7014fb4f0  net-\
snmp-5.7.3.tar.gz" | sha256sum -c

# Verify tarball w/ gpg:
( gpg --list-keys E0F81533 > /dev/null 2>&1 || gpg --recv-keys E0F81533 ) &&
 wget -nc &&
  gpg --verify net-snmp-5.7.3.tar.gz.asc && rm net-snmp-5.7.3.tar.gz.asc

# Extract the source
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "net-snmp-*" -exec rm -r {} \;
tar xzvf ~/net-snmp-5.7.3.tar.gz
cd net-snmp-5.7.3
test $UID = 0 && chown -R root:root .

# If you have MySQL 5.7.x and will be using --with-mysql, apply this patch:
wget -nc\
0001-Detect-if-mysql-has-my_load_defaults-and-use-it-if-s.patch &&
 patch -p1 < 0001-Detect-if-mysql-has-my_load_defaults-and-use-it-if-s.patch

# If you don't have OpenSSL installed in the usual source-installed place
# (/usr/local/ssl), like if you're using a distribution package that puts it
# under the /usr prefix, you can leave off the --with-openssl part.

# To build the Python bindings, either pass --with-python-modules to
# configure (requires the 'setuptools' module), or install them manually
# below

# If you are 64-bit and have a /usr/local/ssl/lib64, put the following at the
# beginning of the configure line:
# LDFLAGS=-L/usr/local/ssl/lib64

# Slackware's package uses --prefix=/usr --sysconfdir=/etc, etc.
# If you want to match paths with that

# Configure the build - 64-bit:
test $(uname -m) = 'x86_64' &&
./configure \
--with-openssl=/usr/local/ssl \
--libdir=/usr/local/lib64 \
--mandir=/usr/local/man \
--docdir=/usr/local/doc/net-snmp \
--with-defaults --with-python-modules --with-mysql

# Configure the build - anything else:
test $(uname -m) != 'x86_64' &&
./configure \
--with-openssl=/usr/local/ssl \
--mandir=/usr/local/man \
--docdir=/usr/local/doc/net-snmp \
--with-defaults --with-python-modules --with-mysql

# Build it

# If you did not use --with-python-modules, but want to install the Python
# bindings:
cd python
python build
su -c "python install"
cd ..

# Become root to remove old files and to install it

# If you're upgrading from ucd to net snmp, remove the old ucd files:
test -d /usr/local/include/ucd-snmp && rm -r /usr/local/include/ucd-snmp
test -d /var/ucd-snmp && rm -r /var/ucd-snmp
rm -f /usr/local/lib/libsnmp* /usr/local/lib/libucdagent* \
# And don't forget to wipe the ucd-snmp tarball and source too.

# If you're replacing a snmpd that was installed into the /usr prefix,
# with config files in /etc/snmp, back up that config file and zap the
# directory
test -f /etc/snmp/snmpd.conf &&
 ( mkdir -p -m 0700 ~/backup
   cp -a /etc/snmp/snmpd.conf ~/backup/snmpd.conf-$(date +%Y%m%d)
   rm -r /etc/snmp )

# You may also want to wipe out /usr/local/share/snmp to make sure
# everything in there is current.  I blow mine away (unless I customize
# files in there) and only back up my snmpd.conf:
test -f /usr/local/share/snmp/snmpd.conf &&
 ( mkdir -p -m 0700 ~/backup
   cp /usr/local/share/snmp/snmpd.conf ~/backup/ )
test -d /usr/local/share/snmp && rm -r /usr/local/share/snmp

# Before continuing, be aware that if you're upgrading net-snmp, any daemons
# that are running that are linked against the libnetsnmp* shared libraries
# may need to be rebuilt to be linked against the new version of the
# libraries.  For example, and older version's libraries may be named
# libnetsnmp*.so.9, but this one's will be libnetsnmp*.so.15
# Try 'lsof /usr/local/lib*/' to see what they are, if any. 
# Either rebuild those apps, or skip the part below that removes old
# versions of the shared library files before running 'make install'.
# Some apps that can use libnetsnmp*.so are:
# Apache + PHP
# cyrus-imap
# freeradius
# and some non-daemon apps that may be running that can use it are:
# Wireshark

# Remove the Slackware package, if there is one
test -x /sbin/removepkg &&
 ( /sbin/removepkg net-snmp
   test -d /var/lib/net-snmp && rm -r /var/lib/net-snmp )

# Remove libraries left over from old versions
for pfx in /usr /usr/local;
  rm -f ${pfx}/lib*/libnetsnmp.*
  rm -f ${pfx}/lib*/libnetsnmpagent.*
  rm -f ${pfx}/lib*/libnetsnmpmibs.*
  rm -f ${pfx}/lib*/libnetsnmphelpers.*
  rm -f ${pfx}/lib*/libnetsnmptrapd.*

# Even if you use --mandir=/usr/local/man above, 'make install' may result
# in man pages for Net::SNMP will end up in /usr/local/share/man
test ! -l /usr/local/share/man &&
 test ! -d /usr/local/share/man &&
  test -d /usr/local/man &&
   ln -s /usr/local/man /usr/local/share/man

# Install the new one
make install

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# See EXAMPLE.conf for a sample /usr/local/share/snmp/snmpd.conf or
# restore yours if you backed one up:
test -f ~/backup/snmpd.conf && cp ~/backup/snmpd.conf /usr/local/share/snmp/

# Recent versions of Slackware include a /etc/rc.d/rc.snmpd init-script.
# If you still have yours, change the path from /usr to /usr/local.
# Here is one that is already fixed:
# Make sure something like /etc/rc.d/rc.M is going to start that script
# on boot-up or snmpd won't start.
# If you don't want to use that one, or if your Slackware doesn't
# have anything in /etc/rc.d/rc.M 
## Add something like this to /etc/rc.d/rc.local to start it on boot-up
#if [ -x /usr/local/sbin/snmpd ]; then
#  echo "Starting net-snmp..."
#  /usr/local/sbin/snmpd

## (Re-)start snmpd
# If you have the script:
/etc/rc.d/rc.snmpd stop
sleep 2
killall snmpd
sleep 2
killall -9 snmpd
/etc/rc.d/rc.snmpd start
# if not:
# killall snmpd > /dev/null 2>&1
# sleep 2
# killall -9 snmpd > /dev/null 2>&1
# /usr/local/sbin/snmpd

# Confirm that the Perl Net::SNMP module is installed/upgraded if you will
# be needing that
perl -MCPAN -e shell
o conf make_install_arg UNINST=1
o conf prerequisites_policy follow
install Bundle::CPAN
install Net::SNMP

# Become yourself again

# Save the source for later
mkdir -p -m 0700 installed
rm -f installed/net-snmp-*.tar.*
mv net-snmp-5.7.3.tar.gz installed/

# If you ever want to uninstall net-snmp, this should do it:
test -x /etc/rc.d/rc.snmpd && /etc/rc.d/rc.snmpd stop
sleep 2
killall snnmpd
sleep 2
killall snmptrapd
test -d src/net-snmp-* && ( cd src/net-snmp-* ; make uninstall )
test -f /etc/rc.d/rc.snmpd && rm -f /etc/rc.d/rc.snmpd
test -d /etc/snmp && rm -r /etc/snmp
for pfx in /usr /usr/local;
  ( cd ${pfx}/bin
    rm -f agentxtrap encode_keychange fixproc mib2c \
     net-snmp-cert net-snmp-config net-snmp-create-v3-user snmp-bridge-mib \
     snmpbulkget snmpbulkwalk snmpcheck snmpconf snmpdelta snmpdf snmpget \
     snmpgetnext snmpnetstat snmpset snmpstatus snmptable snmptest \
     snmptranslate snmptrap snmpusm snmpvacm snmpwalk tkmib traptoemail )
  ( cd ${pfx}/sbin ; rm -f snmpd snmptrapd )
  test -d ${pfx}/include/net-snmp
  rm -f ${pfx}/lib*/libnetsnmp.*
  rm -f ${pfx}/lib*/libnetsnmpagent.*
  rm -f ${pfx}/lib*/libnetsnmpmibs.*
  rm -f ${pfx}/lib*/libnetsnmphelpers.*
  rm -f ${pfx}/lib*/libnetsnmptrapd.*
  for manfile in man/*.1; do rm ${pfx}/man/man1/$(basename $manfile); done
  for manfile in man/*.3; do rm ${pfx}/man/man3/$(basename $manfile); done
  for manfile in man/*.5; do rm ${pfx}/man/man5/$(basename $manfile); done
  test -d ${pfx}/share/snmp && rm -r ${pfx}/share/snmp
find ~/src -maxdepth 1 -type d -name "net-snmp-*" -exec rm -r {} \;
rm -f ~/installed/net-snmp-*.tar.*

Back to the list

Last updated: Wed, 29 Apr 2020 22:04:50 -0400
Jason Englander <jason at englanders dot us>