A curated list of SNMP commands and parameters.
The article aims to highlight differences between RedHat (e.g. AlmaLinux/CentOS) based distributions and Debian (e.g. Ubuntu) based distributions. As a bonus how to setup SNMP on Windows is included.
Table of Contents
AlmaLinux/CentOS
Installation on AlmaLinux
dnf install net-snmp systemctl enable snmpd
Installation on CentOS
yum install net-tools chkconfig snmpd on (CentOS 6) systemctl enable snmpd (CentOS 7)
Configuration
The quick way is a single line:
rocommunity your_secret_public_community ip_address_of_snmp_server
Here is a more extensive template:
rocommunity your_secret_public_community syslocation Rack, Room, Building, City, Country syscontact Your Name <your@email.address> sysDescr Hardware, Serial, Operating System, Platform #Distro Detection extend distro /usr/bin/distro
If you don’t have serial numbers for sysDescr
, you could do something like:
sysDescr Guest, Host, Control Panel, Major Applications
E.g.:
sysDescr VM on SuperDaddy, Dedicated Machine at XYZ, Virtualmin, Email + Web
Distro detection script:
If you’re using LibreNMS or you want your SNMP program to automatically detect the distro, use this script:
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro; chmod +x /usr/bin/distro
Ubuntu
Install on Ubuntu
sudo apt install snmpd
Configuration
The quick single line way works:
rocommunity your_secret_public_community ip_address_of_snmp_server
Here is a more extensive Ubuntu template:
rocommunity your_secret_public_community syslocation Rack, Room, Building, City, Country syscontact Your Name <your@email.address> com2sec readonly your_secret_public_community agentaddress udp:161 sysservices 76 master yes
Windows Server
Windows server setup is UI driven. There are three steps:
- Install the Windows server feature using the server management tool
- Add Roles and Features Wizard
- Next, next, next, click on Features
- SNMP Service which will auto suggest it’s SNMP Tools dependency. You only need those two services.
- Next, next, next, click on Features
- Add Roles and Features Wizard
- In services.exe, right click the newly installed SNMP Service and change on the last tab, both the authentication (e.g. public) and IP address allowed. If you’ve just installed the service you might have to wait around a minute or two for actual right click menus that you need to appear.
Change localhost
to the IP address of your management server.
Enable UDP port 161 in using the firewall tool for the public zone. This might be optional on some systems.
Other Linux
A curated set of configuration commands and options that should work with any distribution
Allow Firewalld
If you’re using Firewalld, use these two commands to quickly allow SNMP through:
firewall-cmd --zone=public --permanent --add-service=snmp; firewall-cmd --reload
Turn off Repetitive Logging
Is your syslog overrun with SNMP connect requests? Try this:
dontLogTCPWrappersConnects yes
Execute your own OID Script
Postfix
This parameter works in conjunction with another script to calculate Postfix queue size.
exec postqueue /etc/postfix/snmp_monitor_postqueue.sh
When you have this as the first “application” for SNMPD, the OID will be:
.1.3.6.1.4.1.2021.8.1.101.1 |
Monitoring Asterisk
When monitoring Asterisk, you might end with these four entries:
exec AsteriskExtensionInUse /usr/bin/sudo /etc/snmp/asterisk_extension_in_use.sh exec AsteriskExtensionNotInUse /usr/bin/sudo /etc/snmp/asterisk_extension_not_in_use.sh exec AsteriskExtensionUnavailable /usr/bin/sudo /etc/snmp/asterisk_extension_unavailable.sh exec AsteriskExtensionRinging /usr/bin/sudo /etc/snmp/asterisk_extension_ringing.sh
Testing with SNMPWalk
A beautiful elegant savvy way of testing your SNMP
For CentOS, you need this:
yum install net-snmp-utils
Then do this:
snmpwalk -c your_secret -v1 host.example.com
Other Interesting Parameters
cat /etc/snmp/snmpd.conf # run as # agentuser root # realStorageUnits 0
See Also
Reference
https://docs.librenms.org/Support/SNMP-Configuration-Examples/#linux-snmpd-v2