SNMP

SNMP lets a management station read and change a device's MIB variables through the agent on the device, and lets the agent report events unasked. A trap is unacknowledged; an inform carries the same news and is acknowledged. Versions 1 and 2c authenticate with a readable community string; SNMPv3 adds authentication with authNoPriv and encryption with authPriv.

In Daveth Pro (Network)10 min video · lab: Find the fault

By , founder of Daveth · Updated

Opening frame of the video walkthrough of SNMP

Watch this lesson

10 min · Video walkthrough

In Daveth Pro (Network)

The full 10 min walkthrough is in Daveth Pro (Network). See what the plan opens

Upcoming practical lab

Lab E14: Find the fault

What the lab covers

What this page answers

What is the difference between an SNMP trap and an inform?

Both are unsolicited messages from an agent to a manager when an event occurs. A trap is unconfirmed: if it is lost, it is lost. An inform is acknowledged by the manager with a response. Read it in “4.1 Managers, agents and the MIB”

What do the SNMPv3 security levels mean?

noAuthNoPriv uses a user name and no protection; authNoPriv adds a digest, so the agent knows who sent the message and that nobody changed it; only authPriv encrypts the request, though the user name still travels in the clear. Read it in “4.1 Managers, agents and the MIB”

4.1 Managers, agents and the MIB

R1 sent a trap when someone changed its configuration. Does the NMS know? Keep that in mind; section 4.2 answers it.

Operations teams rely on devices telling them when something happens, a link going down, a failed login, a power supply dying, and SNMP is the usual tool; it can configure devices too, though that's less common. Three pieces: the agent on the device "contains MIB variables whose values the SNMP manager can request or change"; the manager (the NMS) "uses information in the MIB to perform operations"; the MIB is "the repository for information about device parameters and network data". You can think of it as a library catalogue: every item has a shelf mark, and the manager asks for items by their mark.

Those shelf marks are object identifiers. The guide's Example 24-29 prints part of SNMPv2-MIB, the system group under mib-2 1: sysDescr, sysObjectID and sysUpTime are read-only; sysContact, sysName and sysLocation are read-write; sysUpTime counts hundredths of a second since the device's SNMP agent ("the network management portion of the system") was last re-initialised. Vendors get their own branch under 1.3.6.1.4.1, which is how sysObjectID tells a manager "what kind of box" it's talking to. If you've ever looked up a book by its catalogue number rather than its title, you've done what a manager does with an OID: exact, unambiguous, and useless to anyone without the catalogue.

The two directions have their own ports: agents listen for requests on UDP 161, and managers listen for notifications on UDP 162.

The MIB's own documentation illustrates sysObjectID with "Flintstones, Inc." and its "Fred Router", which is the most honest admission in networking that nobody reads these files for fun.

The manager's side:

OperationWhat it does
get-requestreads one value
get-next-requestreads the next value in order, which is how a manager walks a table
get-bulk-requestreads large blocks, such as many table rows, in one exchange
set-requestwrites a value
responseanswers any of the above (the guide's "get-response")

The agent's side is the notification. A trap is "an unsolicited message from an SNMP agent to an SNMP manager when some event has occurred". An inform carries the same news but is acknowledged: "When an SNMP manager receives an inform request, it acknowledges the message with an SNMP response protocol data unit". The architecture puts it formally: get, get-next, get-bulk, set and inform are the confirmed class, and the trap and the response are unconfirmed. Polling works like a waiter coming to the table to take your order; a trap is a smoke alarm, which goes off whether or not anyone is home.

Predict before reading on: a set to sysLocation using the READONLY community. What comes back? Then: an inform whose first copy is lost. D1 lets you check both.

The difference matters when something goes wrong. Cisco: "Traps are unreliable because the receiver does not send an acknowledgment when it receives a trap, and the sender cannot determine if the trap was received"; an inform "is held in memory until a response is received or the request times out", and "might be resent or retried several times". That answers section 4.1: R1 can't know. Informs cost the sender memory, traps cost you certainty. Just like when you post something important: a normal stamp is cheaper, and recorded delivery is the one that tells you it arrived.

Sets follow two rules. The community must allow writing, and the object must be writable. Ask to change sysUpTime and you'll be refused even with the read/write community, because the MIB defines it read-only: the error is notWritable.

D1

  1. Network drawing: NMS .100, R1 agent

    Step 1 of 3 The NMS at 192.168.14.100 is about to ask R1's agent for one value, using the READONLY community.

  2. Network drawing: NMS .100, R1 agent, GetRequest → UDP 161, sysUpTime.0

    Step 2 of 3 The NMS sends a GetRequest for sysUpTime.0 to UDP port 161 on R1.

  3. Network drawing: NMS .100, R1 agent, GetRequest → UDP 161, sysUpTime.0, Response, sysUpTime.0 = 8640000 (1 day, in hundredths of a second)

    Step 3 of 3 One value, one round trip.

A noAccess error: the read-only community has no write access. The lost inform comes back a second time, and the NMS acknowledges it; a lost trap simply vanishes. A request from 192.168.14.50 gets no answer at all, because ACL 99 only lets 192.168.14.100 in, and the manager just times out.

A trap is the network's version of shouting "fire!" into an empty building and filing it as "incident reported".

Three versions. From v1 to v2c the changes are in the protocol: better error handling, and informs, which v1 can't send. From v2c to v3 they're about security:

ModelLevelAuthenticationEncryption
SNMPv1noAuthNoPrivcommunity stringno
SNMPv2cnoAuthNoPrivcommunity stringno
SNMPv3noAuthNoPrivuser nameno
SNMPv3authNoPrivHMAC-MD5 or HMAC-SHAno
SNMPv3authPrivHMAC-MD5 or HMAC-SHADES (56-bit), 3DES (168-bit) or AES (128, 192, 256-bit)

v1 and v2c use a community string, read-only (RO) for polling or read/write (RW) for pushing changes, and an access list to decide which managers may talk to the device at all. v2c also brings more error codes than v1. A community string works like a password shouted across a crowded room: everyone listening now knows it. The ACL limits which addresses may use it; it doesn't stop anyone hearing it. That's v3's job.

Predict before reading on: which v3 level stops an eavesdropper reading the request, and which only stops a tamperer? D2 lets you check.

v3 replaces the community with users, each a member of a group, and adds levels. authNoPriv adds a digest, so the agent can tell who sent the message and that nobody changed it; the request itself is still readable. Only authPriv encrypts, and even then what's encrypted is the request (the scoped PDU): the user name travels in the clear in the header, because the receiver needs it to know which keys to use. The AES standard for SNMP, RFC 3826, defines 128-bit AES; the 192- and 256-bit options in Cisco's table are Cisco's, so check your NMS supports them. authPriv also needs a software image with cryptography. It's like a sealed envelope with your name on the outside: nobody can read the letter, and everybody can see who it's for.

D2

Network drawing: SNMPv2c (noAuthNoPriv), community · readable, READWRITE, integrity · absent, none, the request (OIDs and values) · readable, set sysLocation.0 = "wiring closet, 2nd floor"
A community string is a password sent in the clear with every message. The ACL on the agent limits which addresses can use it; it doesn’t stop anyone on the path reading it.

authPriv hides it; authNoPriv only makes tampering detectable. The guide calls v3 "very secure" because it uses user names and SHA or MD5, but at authNoPriv that's integrity without secrecy.

SNMPv2c's security model is a password sent in plain text with every single message, which is a bold choice for a protocol that can reconfigure your router.

The guide's device-side list: define the NMS to send traps to, an access list, the RO community, the RW community, the location and the contact; order doesn't matter, but do the ACL first so the device is locked down the moment SNMP comes up. Add NMS hosts to the ACL one by one rather than permitting the whole subnet, which the guide calls more of a security risk, and pick community strings that aren't easy to guess. That habit matters because the first snmp-server community, user or host command is what opens UDP 161 and 162 and enables the agent; by default the agent is disabled.

The guide's R1, with its two slips fixed (it reuses READONLY for the rw line, and its host line has no version keyword, which means v1 although the section is about v2c):

access-list 99 permit 192.168.14.100 0.0.0.0
snmp-server community READONLY ro 99
snmp-server community READWRITE rw 99
snmp-server location telephone closet, 3rd floor
snmp-server contact noc@example.net
snmp-server enable traps config
snmp-server host 192.168.14.100 traps version 2c READONLY

snmp-server enable traps alone enables every trap the platform has, many of them noise; enable the ones you need, and use snmp-server enable traps ? to see what's available, because the list is platform-specific. Out of the box, a 9300 has none enabled except TCP connection (tty) traps. Location and contact are the MIB's sysLocation and sysContact, which is why the guide printed the system group first. Consider it your first-day checklist: the settings are small, and the order is what keeps the door shut while you work.

snmp-server host without a version keyword sends version 1, and v1 can't send informs. The general form is snmp-server host host-addr [traps | informs] [version {1 | 2c | 3 {auth | noauth | priv}}] community-string. A v3 setup from the same guide's syntax, polling plus traps:

snmp-server group NMSGROUP v3 priv access 99
snmp-server user nmsuser NMSGROUP v3 auth sha <auth-password> priv aes 128 <priv-password>
snmp-server host 192.168.14.100 traps version 3 priv nmsuser

Cisco's advice for the group is not to specify a notify view, because snmp-server host generates one. Think about the last time you set up a new phone: the plan (the group) says what's allowed, the account (the user) belongs to a plan, and the notifications (the host) go to an account.

v3 informs need more. For a message that expects a response, the receiver is the authoritative engine, so for an inform that's the NMS, and R1 must know the NMS's engine ID and hold a user for that remote engine. Cisco's instruction: before you configure remote users, "configure the SNMP engine ID, using the snmp-server engineID global configuration command with the remote option". So the inform version adds snmp-server engineID remote 192.168.14.100 <NMS engine ID> and a user with remote 192.168.14.100 in it, before snmp-server host 192.168.14.100 informs version 3 priv nmsuser.

Forget the version keyword on snmp-server host and you've asked for SNMPv1, the one version that can't send the informs you wanted.

A poll is evidence about the agent, and a notification is evidence about the sender's intent. If you've ever posted a letter and assumed it arrived because you put it in the box, you already know which row bites:

ResultProvesDoesn't prove
a get answeredthe agent is up, UDP 161 reached it, and the community and ACL let you inthat the value is fresh everywhere, or that traps work: that's the other direction
a get timing outno answer came backwhy: wrong community, wrong source, an ACL on the path, or the agent is off
config traps enabled and a host setR1 will emit a trap when the configuration changesthat it arrives: traps are never acknowledged
an inform acknowledgedthe NMS received itthat anyone acted on it
a set answered noErrorthe value was writtenthat it was the right value
v3 authNoPriv in usenobody can change messages undetectedthat nobody can read them

Ask on 161, hear on 162; a trap is like a shout, an inform like a signed-for letter.

The "Simple" in Simple Network Management Protocol survived three versions, three security levels and a remote engine ID requirement for informs, which is real commitment to a brand.

So far SNMP has been the plumbing. The blueprint says "diagnose", and that means reading what comes out of it. The guide names the everyday alerts: "link status events, improper user authentication, and power supply failures". The objects behind link events are standard. The interfaces MIB, IF-MIB, keeps a row per interface: "Each interface is identified by a unique value of the ifIndex object", and ifName, in the matching row of the extension table (ifXTable, same ifIndex), is "the name of the interface as assigned by the local device". So ifIndex is the row's number and ifName tells you which port that number is. It's basically like the meter cupboard in a block of flats: one meter per flat, a number on each, a list on the door that says which number is which flat, and a single reading tells you almost nothing.

That's the first rule: a counter is only useful as a difference between two polls. Say the NMS polls a switch port 300 seconds apart:

Object (IF-MIB)Poll 1Poll 2ChangeReading
ifHCInOctets1,000,000,0001,450,000,000450,000,000 octets450,000,000 × 8 / 300 = 12 Mbps in, averaged over 5 minutes
ifInErrors1205,1205,000received packets "that contained errors preventing them from being deliverable": something on this link or the device at its far end is damaging frames
ifOutDiscards40400nothing "chosen to be discarded even though no errors had been detected", whose "possible reason ... could be to free up buffer space": no outbound drops in those five minutes

Now the traps that make the arithmetic worth doing. Picture yourself comparing two gas meter readings a month apart, only to find the meter was replaced in between: the subtraction is nonsense. Counters have the same trap. "Discontinuities in the value of this counter can occur at re-initialization of the management system", and the agent records when in ifCounterDiscontinuityTime. If sysUpTime went down between the polls, the agent restarted and every delta across that point is meaningless; a coldStart notification says the same thing, that the entity "is reinitializing itself". Why ifHCInOctets and not ifInOctets? A 32-bit octet counter wraps fast: "at 100Mbs, the minimum wrap time is 5.7 minutes, and at 1Gbs, the minimum is 34 seconds", so the RFC requires 64-bit octet counters above 20 Mbps. Poll a gigabit port's 32-bit counter every five minutes and it may have wrapped several times; the difference you compute is not the traffic. One catch from section 4.3: the 64-bit counters are a type SNMPv1 can't carry. An agent "MUST NOT ever return a variable binding containing a Counter64 value in a response to a request that was received using the SNMPv1 message version", so poll them with v2c or v3.