Linux SNMP: Simple Network Management Protocol:
SNMP or Simple Network Management Protocol, is a technology standard for alert messages (trap), monitoring (get), and configuring (set) network devices. SNMP comes in three varieties: v1, v2 and v3, of which v3 is the only version to be considered secure.
The variables associated with a network device configuration is defined in the Management Information Base, or MIB. The MIB is a collection of information for managing the network element and is comprised of managed objects identified by the Object Identifier (OID). Each OID is unique and identifies a special characteristic of the managed network device. SNMP is built upon a client (SNMP manager) — server (SNMP agent/network device) architecture pattern with a message schema defined by the MIB and sent over UDP port 161 (SNMP agent) and port 162 (SNMP manager). Each of the data values defined by the MIB are associated with an OID identified by a hierarchy of numbers separated by periods.
Installation:
- CentOS/RedHat: sudo yum install net-snmp-utils net-snmp net-snmp-devel
(RPMs also included with CentOS/RHEL 6 and 7 install DVDs) - Ubuntu: sudo apt-get install snmp snmpd snmp-mibs-downloader
Configure:
- System file /etc/snmp/snmpd.conf
This file default restricts access to localhost only. - User file ~/.snmp/snmp.conf
Start:
- CentOS/RedHat:
- sudo systemctl enable snmpd.service
- sudo systemctl start snmpd.service
- sudo systemctl status snmpd.service
snmpd.service - Simple Network Management Protocol (SNMP) Daemon. Loaded: loaded (/usr/lib/systemd/system/snmpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2019-07-02 17:03:02 PDT; 3s ago Main PID: 345 (snmpd) Memory: 6.8M CGroup: /system.slice/snmpd.service └─345 /usr/sbin/snmpd -LS0-6d -f Jul 02 17:03:01 myhostname systemd[1]: Starting Simple Network Management Protocol (. Jul 02 17:03:02 myhostname snmpd[345]: NET-SNMP version 5.7.2 Jul 02 17:03:02 myhostname systemd[1]: Started Simple Network Management Protocol (S. Hint: Some lines were ellipsized, use -l to show in full.
- sudo systemctl enable snmpd.service
- sudo systemctl start snmpd.service
- sudo systemctl status snmpd.service
Test:
- snmpwalk -v 1 localhost -c public .1.3.6.1
- snmpwalk -v 1 localhost -c public system
- Open firewall to everything (if using iptables): sudo iptables -F
or - if using firewald: sudo firewall-cmd --permanent --new-service=snmp
this command will add service to directory /etc/firewalld/services/
snmp 161/tcp # Simple Net Mgmt Proto snmp 161/udp # Simple Net Mgmt Proto snmptrap 162/tcp # SNMPTRAP snmptrap 162/udp snmp-trap # Traps for SNMP cmip-man 163/tcp # ISO mgmt over IP (CMOT)
- RHEL 7: snmpget -v 1 -c public localhost sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux myhostname 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64
iso.3.6.1.2.1.1.1.0 = STRING: "Linux myhostname 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64"
+--iso(1) | +--org(3) | +--dod(6) | +--internet(1) | +--directory(1) | +--mgmt(2) | | | +--mib-2(1) | | | +--system(1) | | | | | +-- -R-- String sysDescr(1) | | | Textual Convention: DisplayString | | | Size: 0..255 | | +-- -R-- ObjID sysObjectID(2) | | +-- -R-- TimeTicks sysUpTime(3) | | | | | | | +--sysUpTimeInstance(0) | | | | | +-- -RW- String sysContact(4) | | | Textual Convention: DisplayString | | | Size: 0..255 . .
:HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES:UCD-DISKIO-MIB:TCP-MIB:UDP-MIB:MTA-MIB:NETWORK-SERVICES-MIB:SCTP-MIB:RMON-MIB:EtherLike-MIB:LM-SENSORS-MIB:SNMPv2-MIB:IF-MIB:IP-MIB:NOTIFICATION-LOG-MIB:DISMAN-EVENT-MIB:DISMAN-SCHEDULE-MIB:UCD-SNMP-MIB:UCD-DEMO-MIB:SNMP-TARGET-MIB:NET-SNMP-AGENT-MIB:SNMP-MPD-MIB:SNMP-USER-BASED-SM-MIB:SNMP-FRAMEWORK-MIB:SNMP-VIEW-BASED-ACM-MIB:SNMP-COMMUNITY-MIB:IPV6-ICMP-MIB:IPV6-MIB:IPV6-TCP-MIB:IPV6-UDP-MIB:IP-FORWARD-MIB:NET-SNMP-PASS-MIB:NET-SNMP-EXTEND-MIB:UCD-DLMOD-MIB:SNMP-NOTIFICATION-MIB:SNMPv2-TM:NET-SNMP-VACM-MIB /home/userx/.snmp/mibs:/usr/share/snmp/mibs
iso.3.6.1.2.1.1.3.0 = Timeticks: (1310658) 3:38:26.58
iso.3.6.1.4.1.2021.10.1.3.3 = STRING: "0.10"
Command Description snmpcmd options and behavior common to most of the Net-SNMP command-line tools snmpwalk retrieve a subtree of management values using SNMP GETNEXT requests snmpget communicates with a network entity using SNMP GET requests snmpset communicates with a network entity using SNMP SET requests snmptrap sends an SNMP notification to a manager (also snmpinform) snmpgetnext communicates with a network entity using SNMP GETNEXT requests to get the next variable that is lexicographically «next» in the remote entity’s MIB snmptable retrieve an SNMP table and display it in tabular form snmpdelta Monitor delta differences in SNMP Counter values snmptest flexible SNMP application that can monitor and manage information on a network entity snmpdf display disk space usage on a network entity via SNMP snmpusm creates and maintains SNMPv3 users on a network entity snmpstatus retrieves a fixed set of management information from a network entity snmpnetstat display networking status and configuration information from a network entity via SNMP snmpbulkget SNMP application that uses the SNMP GETBULK request to query a network entity efficiently for information snmpbulkwalk retrieve a subtree of management values using SNMP GETBULK requests snmp.conf configuration files for the Net-SNMP applications SNMP Variables Format of specifying variable names to SNMP tools The Object Identifiers (OID)s are used to identify a specific characteristic of a managed device.
- Scalar: managed object with a single instance (a single key to a key-value pair)
- Tabular: multiple data instances such as the rows of a table (e.g. CPU with multiple cores each with its’ own specific charateristics)
SNMP uses ASN.1 (Abstract Syntax Notation One) to define the data types used to build an SNMP message and uses Basic Encoding Rules (BER) to define the data types.
- Primitive Type: type/length(bytes)/data
- integer
- octet (byte, char)
- string
- null
- boolean
- OID
- sequence
- SNMP PDU (Protocol Data Unit) — complex data types specific to SNMP
Installation:
Select the «walk» button to traverse the OIDs.
Acronym Description ASN.1 Abstract Syntax Notation One BER Basic Encoding Rules MIB Management Information Base (data schema for an SNMP device and its variables) OID Object Identifiers (period separated number notation used to define the SNMP device variables) PDU Protocol Data Unit (SNMP packet construction definition) SNMP Simple Network Management Protocol snmpwalk
snmpwalk is an SNMP application that uses SNMP GETNEXT requests to query a network entity for a tree of information.
An object identifier (OID) may be given on the command line. This OID specifies which portion of the object identifier space will be searched using GETNEXT requests. All variables in the subtree below the given OID are queried and their values presented to the user. Each variable name is given in the format specified in variables(5).
If no OID argument is present, snmpwalk will search the subtree rooted at SNMPv2-SMI::mib-2 (including any MIB object values from other MIB modules, that are defined as lying within this subtree). If the network entity has an error processing the request packet, an error packet will be returned and a message will be shown, helping to pinpoint why the request was malformed.
If the tree search causes attempts to search beyond the end of the MIB, the message «End of MIB» will be displayed.
OPTIONS
Do not check whether the returned OIDs are increasing. Some agents (LaserJets are an example) return OIDs out of order, but can complete the walk anyway. Other agents return OIDs that are out of order and can cause snmpwalk to loop indefinitely. By default, snmpwalk tries to detect this behavior and warns you when it hits an agent acting illegally. Use -Cc to turn off this check.
End the walk at the specified OID, rather than a simple subtree. This can be used to walk a partial subtree, selected columns of a table, or even two or more tables within a single command.
Include the given OID in the search range. Normally snmpwalk uses GETNEXT requests starting with the OID you specified and returns all results in the MIB subtree rooted at that OID. Sometimes, you may wish to include the OID specified on the command line in the printed results if it is a valid OID in the tree itself. This option lets you do this explicitly.
In fact, the given OID will be retrieved automatically if the main subtree walk returns no useable values. This allows a walk of a single instance to behave as generally expected, and return the specified instance value. This option turns off this final GET request, so a walk of a single instance will return nothing.
Upon completion of the walk, print the number of variables found.
Upon completion of the walk, print the total wall-clock time it took to collect the data (in seconds). Note that the timer is started just before the beginning of the data request series and stopped just after it finishes. Most importantly, this means that it does not include snmp library initialization, shutdown, argument processing, and any other overhead.
In addition to these options, snmpwalk takes the common options described in the snmpcmd(1) manual page.
EXAMPLES
Note that snmpwalk REQUIRES an argument specifying the agent to query and at most one OID argument, as described there. The command:
snmpwalk -Os -c public -v 1 zeus system
will retrieve all of the variables under system:
sysDescr.0 = STRING: «SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m»
sysObjectID.0 = OID: enterprises.hp.nm.hpsystem.10.1.1
sysUpTime.0 = Timeticks: (155274552) 17 days, 23:19:05
sysContact.0 = STRING: «»
sysName.0 = STRING: «zeus.net.cmu.edu»
sysLocation.0 = STRING: «»
sysServices.0 = INTEGER: 72
(plus the contents of the sysORTable).snmpwalk -Os -c public -v 1 -CE sysORTable zeus system
will retrieve the scalar values, but omit the sysORTable.
SEE ALSO
snmpcmd(1), snmpbulkwalk(1), variables(5).