Net-SNMP Essentials: A Beginner’s Guide to SNMP Tools and ConfigurationSimple Network Management Protocol (SNMP) is a foundational protocol for monitoring and managing devices on IP networks. Net-SNMP is a widely used, open-source suite of applications and libraries that implement SNMP for Unix-like systems (and Windows), providing tools for querying agents, running agents, building MIB-aware applications, and extending SNMP behavior. This guide introduces core concepts, installation, basic commands, configuration, security, MIBs, and practical examples to get you started.
What is Net-SNMP?
Net-SNMP is an implementation of SNMP (versions 1, 2c, and 3) consisting of:
- Agent daemons (snmpd) that run on managed devices and expose management data.
- Client utilities (snmpget, snmpwalk, snmpbulkget, snmpset, snmptrap, etc.) to query agents or send traps.
- Libraries and development headers for building SNMP-aware software.
- MIB compilers and tools to parse and use Management Information Base (MIB) definitions.
Net-SNMP supports SNMPv1, SNMPv2c, and SNMPv3, with SNMPv3 providing strong authentication and optional encryption.
Core SNMP Concepts (brief)
- Agent: The software on a device that reports management data (snmpd).
- Manager: The monitoring system that queries agents (uses client tools or a management platform).
- OID (Object Identifier): A numerical path in the MIB tree identifying a managed object (e.g., .1.3.6.1.2.1.1.5.0 for sysName.0).
- MIB: Management Information Base — hierarchical definitions of objects exposed by agents.
- Community string: SNMPv1/v2c shared “password” that grants read/write access depending on configuration.
- Trap/Inform: Asynchronous notifications from agent to manager (trap) or with acknowledgment (inform).
Installing Net-SNMP
On Debian/Ubuntu:
sudo apt update sudo apt install snmp snmpd snmp-mibs-downloader libsnmp-dev
On CentOS/RHEL:
sudo yum install net-snmp net-snmp-utils net-snmp-libs
On macOS (Homebrew):
brew install net-snmp
On Windows: Use the Net-SNMP Windows installer from the project site or package repositories.
After installation, the main agent binary is usually /usr/sbin/snmpd. Client tools (snmpget, snmpwalk, etc.) are in PATH.
Default Configuration and Starting the Agent
The agent’s main config file is typically /etc/snmp/snmpd.conf.
A minimal configuration for read-only access via SNMPv2c:
rocommunity public default -V systemonly
This grants read-only access to the community string “public” but limits the view to basic system data.
Start and enable the service (systemd):
sudo systemctl enable --now snmpd sudo systemctl status snmpd
On systems without systemd, use the platform’s service management tools.
Basic Net-SNMP Commands
- snmpget — retrieve one or more OID values
- snmpwalk — walk a subtree of the MIB
- snmpbulkwalk / snmpbulkget — efficient retrieval for many values (SNMPv2c/v3)
- snmpset — set writable OIDs (use with care)
- snmptrap / snmpinform — send traps/informs to managers
- snmptranslate — translate between names and numeric OIDs
- snmpstatus, snmpdf, snmpgetnext — various utilities
Examples (SNMPv2c, community “public”, target 192.0.2.10):
snmpget -v2c -c public 192.0.2.10 .1.3.6.1.2.1.1.5.0 snmpwalk -v2c -c public 192.0.2.10 .1.3.6.1.2.1.1
For SNMPv3 the commands include authentication/encryption flags:
snmpget -v3 -u myuser -l authPriv -a SHA -A authpass -x AES -X privpass 192.0.2.10 sysName.0
Configuring SNMPv3 (recommended)
SNMPv3 provides user-based security (authentication and optional privacy). Steps:
- Create a user and set auth/privacy protocols. Use net-snmp’s snmpusm or the snmpd.conf style.
Using snmpd.conf (example):
createUser myuser SHA authpass AES privpass rwuser myuser
Or using net-snmp tools (example):
# add user to the agent's persistent database sudo net-snmp-create-v3-user -ro -A authpass -X privpass -a SHA -x AES myuser
-
Restrict access and views:
rouser myuser # or finer-grained views with access control
-
Restart snmpd:
sudo systemctl restart snmpd
SNMPv3 client example:
snmpwalk -v3 -u myuser -l authPriv -a SHA -A authpass -x AES -X privpass 127.0.0.1 .1.3.6.1.2.1.1
MIBs and OIDs
MIB files (.txt or .my) define human-readable names for OIDs. Net-SNMP uses MIB directories (commonly /usr/share/snmp/mibs). To enable MIB name resolution, ensure the MIBs are installed and either set MIBS=ALL or pass -m ALL to client commands.
Translate between numeric OID and name:
snmptranslate -On sysName.0 snmptranslate -Td IF-MIB::ifTable
Create custom MIB entries when you need to expose device-specific data. Use the SMI syntax and load the MIB in snmpd.conf if necessary.
Extending snmpd: pass, pass_persist, and extend
- pass: runs a script and returns output; useful for one-off commands.
- pass_persist: runs a long-lived helper process to reduce overhead.
- extend: a simpler way to expose scripts/commands via the AgentX sub-agent mechanism.
Examples in snmpd.conf:
# simple pass: runs script for OID subtree pass .1.3.6.1.4.1.2021.255 /usr/local/bin/my-snmp-script # extend: exposes as UCD-SNMP-MIB::extOutput extend myscript /usr/local/bin/my-script.sh
pass_persist example helper must follow net-snmp persist protocol.
After adding, restart snmpd and query the extended OID or the extOutput table:
snmpwalk -v2c -c public 127.0.0.1 NET-SNMP-EXTEND-MIB::nsExtendOutput1Table
Traps and Notification Configuration
Traps are configured in snmpd.conf. Example to send traps to a manager at 198.51.100.5 using SNMPv2c community “trapcomm”:
trapsink 198.51.100.5 trapcomm # or with SNMPv3 trapsess -v3 -u myuser -l authPriv -a SHA -A authpass -x AES -X privpass 198.51.100.5
To generate test traps:
snmptrap -v2c -c trapcomm 198.51.100.5 '' NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification
On the manager side, ensure the management system listens for traps and correlates them with MIB definitions.
Security Best Practices
- Prefer SNMPv3 with authentication and privacy; avoid SNMPv1/v2c on untrusted networks.
- Use strong passwords (auth and priv), and modern algorithms (SHA, AES).
- Restrict access by source IP and MIB views in snmpd.conf.
- Disable or remove default community strings (“public”, “private”).
- Run snmpd with least privileges and monitor logs for suspicious activity.
- Use firewall rules to allow SNMP only from trusted managers.
Troubleshooting Tips
- If snmpwalk returns “Timeout,” check firewall, agent running, and correct community/user credentials.
- Use tcpdump/wireshark to inspect packets: SNMP uses UDP/161 (requests) and UDP/162 (traps) by default.
- Increase verbosity of snmpd for debugging: start with -f -Lo -DALL option for foreground logging.
- Ensure MIBs are installed for name resolution; otherwise use numeric OIDs.
- For SNMPv3 issues, verify time synchronization (not required by protocol itself usually, but helpful for correlating events), and confirm user exists in agent’s database.
Example: Basic Monitoring Workflow
- Install snmpd on target hosts with SNMPv3 users created.
- Configure a central monitoring system (e.g., Nagios, Zabbix, Icinga, LibreNMS) with the same SNMPv3 credentials.
- Import relevant MIBs into the monitoring platform so it can display friendly names.
- Add checks: sysUpTime, CPU/memory via UCD-SNMP-MIB or HOST-RESOURCES-MIB, interface stats via IF-MIB.
- Configure trap reception for asynchronous alerts (link down, high CPU).
- Harden configurations and test by simulating faults.
Further Resources and Learning Path
- Read the Net-SNMP man pages (snmpd.conf(5), snmpd(8), snmpcmd(1)).
- Study common MIBs: SNMPv2-MIB, IF-MIB, UCD-SNMP-MIB (UCD/SNMP Utils), HOST-RESOURCES-MIB.
- Practice with a lab: run snmpd in containers or VMs and exercise snmpwalk/snmpget/snmptrap.
- Explore scripting extensions (pass/persist/extend) to expose custom metrics.
Net-SNMP is powerful and flexible: start with basic read-only monitoring, move to SNMPv3 for secure production use, and extend the agent with scripts or custom MIBs as your needs grow.
Leave a Reply