How to set up SNMP for CentOS

Background

This guide explains how to install SNMP on CentOS.

Procedure

Install the core library. Please note, this excludes snmpwalk:

yum install net-snmp

Later in this procedure we refer to snmpwalk. If you want to follow that part of the tutorial, install this too:

yum install net-snmp-utils

By default the service won’t be started. You can check it and then start it:

service snmpd status
service snmpd start

The baseline smtpd.conf has too much information. You probably only want to read the public community and not the entire manual so let’s backup the config file and do a one liner:

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.backup
vi /etc/snmp/snmpd.conf

Add just this line:

rocommunity secret_password

Restart the service:

service snmpd restart

Checking the Service

The snmpwalk utility can be used to see if the SNMP service is operational.

Often systems are checked from remote locations, which is also a good way to see if the firewall access is correct.

Here is an example test:

snmpwalk -c secret_password -v1 www.hostname.com

Firewall Considerations

SNMP uses UDP port 161 so make sure this is open on your firewall.

WHM/cPanel CSF

If you’re using WHM/cPanel, add the remote IP address of your testing server like below:

csf -a 1.2.3.4

Automatic Restart after Server Reboot

SNMP has a habit of not starting up after a server is shutdown. Avoid that by doing the command below:

chkconfig snmpd on

The output of chkconfigshould be:

Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.

Troubleshooting SNMP

Troubleshooting SNMP can be a complete nightmare. The configuration files are huge and when you’re dealing with something like SNMP version 3 the options enormous. The default SNMP configuration file supplied with some systems is totally overwhelming.

But if you understand firewall theory and troubleshooting firewall issues, and if your using snmpwalk to troubleshoot, you’ll get far. Otherwise refer to the first two references listed below:

snmpwalk: No securityName specified

Add -v2c to test, e.g.

snmpwalk -c secret localhost -v2c

See Also

How to monitor Postfix queue length using an SNMP monitor

Reference

How to get SNMP daemon working on Ubuntu 18.04/20.04 LTS

Additional Information

This article was updated to remove the reference to net-snmp-utils as it’s not needed for a baseline install.

Tags

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top