The parts of SNMP
| Part | What it is | In this lab |
|---|---|---|
| Manager (NMS) | The system that asks and receives alerts | LibreNMS, 192.168.20.60 |
| Agent | The SNMP process on each device | R1 |
| MIB | The agent's database, shaped like a tree | SNMPv2-MIB, IF-MIB and Cisco MIBs |
| OID | The numeric identifier of each value | 1.3.6.1.2.1.1.3.0 = sysUpTime.0 |
SNMP is used to monitor (read states and counters, receive alerts) and, less often, to configure. Today it coexists with streaming telemetry and APIs (NETCONF and RESTCONF), but it is still the backbone of monitoring.
The messages
| Message | Sent by | Purpose |
|---|---|---|
| get-request | Manager | Read one or more values |
| get-next-request | Manager | Read the next value in the tree (walk a table) |
| getBulkRequest | Manager | Read many rows in a single request (since v2) |
| set-request | Manager | Change a value |
| response | Agent | Answer any of the above |
| trap | Agent | Report an event, without acknowledgment |
| inform | Agent | Report an event, with acknowledgment |
Ports: the agent listens on UDP 161; the manager receives traps and informs on UDP 162.
How it works: asking, reading a table, getting alerts and protecting it all
Five steps: a get, a getBulk, a trap, SNMPv3 discovery and an authPriv query.
get-request: the manager asks for three values
LibreNMS sends R1 a get-request over UDP 161 with three OIDs: sysName.0, sysUpTime.0 and ifOperStatus.4. The values go as NULL: the agent fills them in. R1 checks the community (snmp-server community N0c-Lectura RO) and that the source is in ACL SNMP-NMS, and answers with the same request-id: R1, up for 42 days, and interface 4 up. The whole message is BER-encoded: type, length and value, nested. Look at the inspector: the community can be read as is. Anyone who captures the traffic gets it. That is why SNMPv2c is limited to read-only with an ACL, or replaced by SNMPv3.
getBulkRequest: a table in a single request
To read the interface table, SNMPv1 needed one get-next per value. SNMPv2 added getBulkRequest: the manager asks for two columns (ifDescr and ifOperStatus) and max-repetitions 4, and R1 returns the next four rows of each in a single response: 8 variables. The number at the end of each OID is the ifIndex, the interface's index in the MIB (show snmp mib ifmib ifindex maps it to its name). This is how a monitoring system works: every few minutes it reads counters and states from all interfaces and draws graphs.
snmpV2-trap: R1 reports without being asked
Polling every few minutes is not enough to learn about a failure right away. With snmp-server enable traps snmp linkdown linkup and snmp-server host 192.168.20.60 version 2c N0c-Traps, R1 sends an snmpV2-trap as soon as Gi0/0/3 goes down. The first two variables are always sysUpTime.0 (when it happened) and snmpTrapOID.0 (what happened: linkDown). Then come the interface data: ifIndex, ifDescr, ifType and Cisco's own locIfReason. The trap goes to UDP 162 and gets no reply: if it is lost, nobody knows. To get an acknowledgment there are informs (informRequest).
SNMPv3: first, discover the engineID
SNMPv3 replaces the community with users that have authentication and encryption (the USM model). The keys are derived from the password and the agent's engineID, so the manager needs to know it first. It sends an empty, unsecured get-request with the reportable flag. R1 replies with a report: usmStatsUnknownEngineIDs, and its header carries its engineID (800000090300005E005301: Cisco + R1's MAC), how many times it has rebooted (engineBoots 7) and how many seconds it has been up (engineTime). That time protects against replayed messages: one more than 150 s off is dropped.
authPriv: the same query, authenticated and encrypted
Now the manager asks for sysUpTime.0 as user noc-snmp, at the authPriv level (msgFlags 0x07). Authentication is an HMAC-SHA-96 of the whole message with a key derived from the password and R1's engineID: if anyone changes a byte, R1 drops it. The PDU is encrypted with AES-128 in CFB mode; the initialization vector comes from engineBoots, engineTime and an 8-byte salt. The capture only shows random bytes: the inspector overlays what they carry, decrypted with the keys on this page. R1 answers the same way, authenticated and encrypted. The passwords never travel.
Versions
| Version | Security | Use today |
|---|---|---|
| SNMPv1 | Clear-text community | Old devices |
| SNMPv2c | Clear-text community; adds getBulk and inform | Very common, read-only and with an ACL |
| SNMPv3 noAuthNoPriv | User, no authentication or encryption | Almost never |
| SNMPv3 authNoPriv | Authentication (HMAC-SHA) | When the data need not be hidden |
| SNMPv3 authPriv | Authentication and encryption (AES) | The recommended one |
Configure on IOS XE
| What | Command |
|---|---|
| Read-only community with an ACL | snmp-server community N0c-Lectura RO SNMP-NMS |
| SNMPv3 group with encryption | snmp-server group NOC v3 priv |
| SNMPv3 user | snmp-server user noc-snmp NOC v3 auth sha … priv aes 128 … |
| Trap destination | snmp-server host 192.168.20.60 version 2c N0c-Traps |
| Which traps to send | snmp-server enable traps snmp linkdown linkup |
| Verify | show snmp, show snmp user, show snmp group, show snmp engineID |
SNMPv3 users are not stored in the running configuration: they do not show up in show running-config. You see them with show snmp user.
Frequently asked questions
What is the difference between a trap and an inform?
Both are alerts the agent sends. A trap gets no reply: if it is lost, nobody knows. An inform is acknowledged with a response, and the agent resends it if the acknowledgment does not arrive.
Why is SNMPv3 recommended?
Because in v1 and v2c the community travels in clear text and is enough to read (or, with RW, change) the MIB. SNMPv3 uses users with authentication (HMAC-SHA) and encryption (AES), and protects against replayed messages with engineBoots and engineTime.
What is an OID?
A numeric identifier in the MIB tree. For example, 1.3.6.1.2.1.1.3.0 is sysUpTime.0: iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1).sysUpTime(3), instance 0.
Can SNMP change the configuration?
Yes, with set-request and an RW community or a user with a write view. It is uncommon and risky; for configuration NETCONF, RESTCONF or tools like Ansible are preferred.
Why does the manager first send an empty message in SNMPv3?
Because USM keys are computed with the agent's engineID, and the manager needs to know it. The report it gets back carries the engineID, engineBoots and engineTime.
What you take away
- SNMP has a manager (NMS) that asks and agents on the devices that answer and send alerts.
- Every value in the MIB has an OID; the manager reads with get, get-next and getBulk, and changes values with set.
- The agent listens on UDP 161; traps and informs go to the manager on UDP 162.
- A trap is not acknowledged; an inform is.
- SNMPv1 and v2c use a clear-text community; SNMPv3 adds users, authentication and encryption.
- To verify: show snmp, show snmp user, show snmp group and show snmp engineID.
NEXT STEP
From this lesson to the CCNA 2.0 Course
SNMP, syslog and network management (domain 5.0) are part of The House of Routing's CCNA 2.0 Course, with the Canadá Logística lab. We will let you know when it opens.
Upcoming protocol lessons
Sources
- Cisco · IOS XE 17 configuration guides (Network Management: SNMP Configuration Guide)
- IETF · RFC 3416 · Version 2 of the Protocol Operations for SNMP
- IETF · RFC 3414 · User-based Security Model (USM) for SNMPv3
- IETF · RFC 3826 · The AES Cipher Algorithm in the SNMP User-based Security Model
- Cisco · 200-301 CCNA v2.0 Exam Topics (5.4)
Lesson prepared with AI assistance and checked against the sources cited. The bytes of every packet are generated according to the standard and verified with an independent tool.