Packetwatch.net

SNMP in FreeBSD



Last modified: Oct. 29, 2010

Contents
1 - Summary
2 - Dependencies
3 - Service configuration
4 - Snmpget example
5 - Service check


1 - Summary

This guide will show how to install SNMP in FreeBSD. SNMP is a network protocol
used to monitor network devices. FreeBSD includes BSNMP in the base install.
This has been tested in FreeBSD 8.1.


2 - Dependencies

Install the bsnmp-ucd packge.
# sudo pkg_add -r bsnmp-ucd
Password:


3 - Service configuration

Edit /etc/rc.conf.local so that the bsnmp service will start when the system
starts up. Somewhere in the file add the following.
  bsnmpd_enable="YES"
# sudo vi /etc/rc.conf.local
Password:

The configuration file is located at /etc/snmpd.config. You can create your own
configuration file. For this example, we will use a read only community name of
public. Keep the default configuration file as is except set the following
lines. Also, add the last line to use the UCD MIB files.
  location := "Test"
  contact := "John Doe"
  read := "public"
  #write := "geheim"
  begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"
  begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
# sudo cp /etc/snmpd.config /etc/snmpd.config.example
Password:
# sudo vi /etc/snmpd.config
Password:

Before starting the service, make sure that udp port 161 is open in case you
are running firewall software. Here is a sample rule.
# su - root
Password:
  ext_if="em0"
  udp_services={ 161 }"
  pass in on $ext_if proto udp from any to ($ext_if) port $udp_services flags keep state
# cp /etc/pf.conf /etc/pf.conf.previous
# vi /etc/pf.conf
# pfctl -F all && pfctl -f /etc/pf.conf
# logout

Start the bsnmp service.
# sudo /etc/rc.d/bsnmpd start
Password:
Starting bsnmpd.
# sudo /etc/rc.d/bsnmpd status
Password:
bsnmpd is running as pid 69561.


4 - Snmpget example

The FreeBSD MIB files will need to be copied to the computer that is running
snmpget. The FreeBSD MIB files are stored in /usr/share/snmp/mibs/. In our
example, we are running snmpget from a FreeBSD computer. Find where the MIB
files are stored and copy the files to that directory. Afterwards, run snmpget.
# pkg_info -L net-snmp-* | grep /mibs/
/usr/local/share/snmp/mibs/AGENTX-MIB.txt
...
# sudo chown root:wheel ~/freebsd_mibs/*
Password:
# sudo cp ~/freebsd_mibs/* /usr/local/share/snmp/mibs/
Password:

From another computer, run snmpget to view some SNMP information.
# sudo snmpget -Os -c public -v 2c server.test.com sysName.0 sysLocation.0 sysContact.0
Password:
sysName.0 = STRING: server.test.com
sysLocation.0 = STRING: Test
sysContact.0 = STRING: John Doe


5 - Service check

Reboot your computer. Log in like normal and check to see that the bsnmp
service is running. That's it, now you have SNMP running in FreeBSD.
# sudo shutdown -r now
Password:
# sudo /etc/rc.d/bsnmpd status
Password:
bsnmpd is running as pid 977.


Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2024.