SNMP agent on Linux: setup, configuration and useful OIDs
Install and configure net-snmp, test with snmpwalk, and a list of OIDs for load, CPU, memory and disk.
Practical notes on installing and configuring an SNMP agent (net-snmp) on Linux, testing it with snmpwalk, and a list of useful OIDs for load, CPU, memory and disk monitoring.
Install and enable the agent
yum -y install net-snmp net-snmp-utils
Enable and restart the service:
# RHEL/CentOS 6
chkconfig snmpd on
service snmpd restart
# RHEL/CentOS 7 and later
systemctl enable snmpd
systemctl restart snmpd
Configure a read-only community
Keep a copy of the original file, then edit it:
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
vim /etc/snmp/snmpd.conf
Minimal snmpd.conf granting read-only access through a security name, a group and a view (see the Arch Wiki snmpd page for the access control model):
# sec.name source community
com2sec monUser default readonly_community
# Map the security name into a group name
# groupName securityModel securityName
group monGroup v1 monUser
group monGroup v2c monUser
# Create a view the group can read
# name incl/excl subtree mask(optional)
view systemview included .1
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
# Grant the group read-only access to the view
# group context sec.model sec.level prefix read write notif
access monGroup "" any noauth exact systemview none none
Change the listening port
Options can be passed to the daemon through /etc/sysconfig/snmpd (see this guide). Example moving the agent to port 13371:
echo OPTIONS=\"-LS0-5d -Lf /dev/null -x TCP:13371 UDP:13371\" >> /etc/sysconfig/snmpd
snmpwalk -v 2c -c readonly_community -O e 127.0.0.1:13371
Ubuntu / Debian variant
On Debian-based systems a drop-in file such as /etc/snmp/snmpd.conf.d/20-monitoring.conf can hold the same directives, with an additional view for the monitoring tool and automatic disk monitoring:
com2sec monUser default readonly_community
group monGroup v1 monUser
group monGroup v2c monUser
view systemview included .1
view monitoring included .1.3.6.1
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access monGroup "" any noauth exact monitoring none none
access monGroup "" any noauth exact systemview none none
includeAllDisks 10%
To allow remote queries, comment out the loopback-only listening line in /etc/snmp/snmpd.conf:
#agentaddress 127.0.0.1,[::1]
Test and check
# SNMP v3
snmpwalk -v3 -l authPriv -u snmp_user -a MD5 -A <PASSWORD> -x AES -X <PASSWORD> 192.0.2.10:6033 .1.3.6.1.4.1.2021.4
# SNMP v2c: memory and process table
snmpwalk -v 2c -c readonly_community host01 1.3.6.1.4.1.2021.4
snmpwalk -v 2c -c readonly_community host01 1.3.6.1.2.1.25.4.2.1
Check that polling requests reach the server (replace the IP with the monitoring server):
sudo tcpdump -n -i eth0 host 192.0.2.10 and not arp
sudo tail -n 500000 /var/log/messages | grep "Connection from UDP: \[192.0.2.10\]" | wc -l
On Windows, check whether the trap port is open:
netstat -ano | findstr 162
Ports 161 (queries) and 162 (traps) should be blocked at the firewall from untrusted networks.
Useful OIDs (net-snmp)
| Metric | OID |
|---|---|
| Load 1 / 5 / 15 min | .1.3.6.1.4.1.2021.10.1.3.1 / .2 / .3 |
| User CPU % | .1.3.6.1.4.1.2021.11.9.0 |
| System CPU % | .1.3.6.1.4.1.2021.11.10.0 |
| Idle CPU % | .1.3.6.1.4.1.2021.11.11.0 |
| Raw user / nice / system / idle CPU time | .1.3.6.1.4.1.2021.11.50.0 / .51.0 / .52.0 / .53.0 |
| Total swap | .1.3.6.1.4.1.2021.4.3.0 |
| Available swap | .1.3.6.1.4.1.2021.4.4.0 |
| Total RAM | .1.3.6.1.4.1.2021.4.5.0 |
| RAM used | .1.3.6.1.4.1.2021.4.6.0 |
| RAM free | .1.3.6.1.4.1.2021.4.11.0 |
| RAM shared | .1.3.6.1.4.1.2021.4.13.0 |
| RAM buffered | .1.3.6.1.4.1.2021.4.14.0 |
| Cached memory | .1.3.6.1.4.1.2021.4.15.0 |
| System uptime | .1.3.6.1.2.1.1.3.0 |
Memory usage can be derived from these values: (memAvailReal + memBuffer + memCache) / memTotalReal.
Disk statistics
Add a disk directive to snmpd.conf first, for example disk / 100000 for a single / partition, or includeAllDisks 10% for all partitions.
| Metric | OID |
|---|---|
| Mount path | .1.3.6.1.4.1.2021.9.1.2.1 |
| Device path | .1.3.6.1.4.1.2021.9.1.3.1 |
| Total size (kB) | .1.3.6.1.4.1.2021.9.1.6.1 |
| Available space | .1.3.6.1.4.1.2021.9.1.7.1 |
| Used space | .1.3.6.1.4.1.2021.9.1.8.1 |
| Space used % | .1.3.6.1.4.1.2021.9.1.9.1 |
| Inodes used % | .1.3.6.1.4.1.2021.9.1.10.1 |
AIX
An AIX agent exposes CPU and memory under the .1.3.6.1.4.1.2.3.1.2.2.2.1 subtree (for example xmdCPUGluser .1.3.6.1.4.1.2.3.1.2.2.2.1.1.101, xmdMemRealEfree .1.3.6.1.4.1.2.3.1.2.2.2.1.2.1.10). Memory details are also under .1.3.6.1.4.1.2.6.191 (OID reference).
snmpwalk -v 1 -c readonly_community 192.0.2.17 1.3.6.1.4.1.2.6.191.9.4.1
Windows
Install the "SNMP Service" Windows feature, then configure it in the service properties:
- Agent tab: contact and location.
- Traps tab: community name and trap destination.
- Security tab: accepted community names (read only) and the hosts allowed to send SNMP packets.
Useful tools: snmputil.exe (Resource Kit), SnmpWalk.exe, SnmpTrapGen.exe, TrapGen.exe, SNMPtrap.exe, a MIB browser.
snmpwalk.exe -r:127.0.0.1
SnmpTrapGen.exe -r:192.0.2.11 -t:10 -c:"public" -to:.1.3.6.1 -val:"test" -vtp:str -vid:.1.3.6.1.2.1.1.4.200
TrapGen -d 192.0.2.11 -c public -v .1.3.6.1.4.1.2349.2.2.2.7 STRING "Test alert"
To list all OIDs of a device (modem, appliance):
snmpwalk -c public -v 1 -Ofn 192.0.2.15
Notes
- Use SNMP v3 with authentication and encryption whenever possible; community strings are sent in clear text with v1/v2c.
- Do not keep the default
publiccommunity on production systems.