net-snmp
Net-SNMP is the standard, near-universal command-line SNMP toolkit on Linux - snmpget, snmpwalk, snmpset, and friends all come from this same project. This guide covers installing it, the core commands, and how to get MIB names resolving instead of raw OID numbers.
Installing net-snmp
# Debian / Ubuntu
sudo apt update
sudo apt install snmp snmp-mibs-downloader
# RHEL / CentOS / Fedora
sudo dnf install net-snmp net-snmp-utils
# (older systems: sudo yum install net-snmp net-snmp-utils)
The snmp/net-snmp-utils package gives you the client tools covered below. Building or configuring an actual SNMP agent (snmpd) on the machine itself is a separate topic, covered on the SNMP Service guide.
Basic usage
The core commands share the same connection flags: -v for SNMP version, -c for the community string (v1/v2c), and the target host/OID at the end.
# Get a single value
snmpget -v2c -c public 192.168.1.1 sysDescr.0
# Walk an entire subtree
snmpwalk -v2c -c public 192.168.1.1 system
# Faster walk for large tables (uses GETBULK instead of repeated GETNEXT)
snmpbulkwalk -v2c -c public 192.168.1.1 ifTable
# Set a writable value (needs a community with write access)
snmpset -v2c -c private 192.168.1.1 sysContact.0 s "admin@example.com"
# Render a table as an actual table instead of one row per line
snmptable -v2c -c public 192.168.1.1 ifTable
For SNMPv3, the version flag changes and you authenticate with a username and security parameters instead of a community string:
snmpget -v3 -u myuser -l authPriv -a SHA -A 'authpassword' -x AES -X 'privpassword' 192.168.1.1 sysDescr.0
Loading MIBs
Without MIBs loaded, every result prints as a raw numeric OID. Net-SNMP looks for MIB files in a search path made up of a few default locations plus anything you add:
- Default directories — typically
/usr/share/snmp/mibs(system-wide) and~/.snmp/mibs(per-user). Drop a.txt/.mibMIB file in either and it's picked up automatically on the next run. - The
MIBSenvironment variable — controls which loaded MIBs are actually used for translating OIDs.export MIBS=+ALLloads everything found in the search path (verbose, but reliable);export MIBS=+IF-MIB:CISCO-PROCESS-MIBloads specific ones. -m— load specific MIBs for a single command, without touching the environment:snmpwalk -m +CISCO-PROCESS-MIB -v2c -c public 192.168.1.1 cpmCPUTotal5minRev.-M— add an extra directory to the MIB search path:snmpwalk -M +/opt/custom-mibs -m +MY-CUSTOM-MIB ....
To make a setting permanent rather than passing flags every time, add it to /etc/snmp/snmp.conf (system-wide) or ~/.snmp/snmp.conf (per-user):
mibdirs +/opt/custom-mibs
mibs +ALL
Example: putting it together
Walking a Cisco device's CPU utilization, with the vendor MIB loaded so the result comes back as a readable name instead of a bare OID:
snmpwalk -m +CISCO-PROCESS-MIB -v2c -c public 192.168.1.1 cpmCPUTotal5minRev
CISCO-PROCESS-MIB::cpmCPUTotal5minRev.1 = INTEGER: 4
Without -m +CISCO-PROCESS-MIB loaded (and no MIBS=+ALL set), the same walk would instead print the raw OID (.1.3.6.1.4.1.9.9.109.1.1.1.1.8.1) with no name attached - functionally the same data, just harder to read at a glance.