Computer Networks / Practical class / Practical class 18
Practical class · Computer Networks

SNMP – the network monitoring protocol

A university network has hundreds of switches, routers, printers and servers. How does the administrator know which port has “gone down”, which link is 90% loaded, or that a printer has run out of paper? He does not visit every device one by one — he asks through SNMP, and the devices themselves also send a “signal”. Today you will get to know the SNMP architecture, the MIB and the OID tree, read snmpwalk results and write monitoring programs in Python that calculate link load.

:ik-kitob: Practical class 18 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ The heartbeat of the network
18

Lesson goals and plan

By the end of the lesson you will…

  • you can explain the SNMP architecture (manager, agent, MIB) and the role of UDP ports 161/162
  • you can distinguish the SNMP operations (Get, GetNext, GetBulk, Set, Response, Trap, Inform)
  • you can read the OID tree and find the main objects under 1.3.6.1.2.1 (mib-2) (sysDescr, sysUpTime, ifTable)
  • you can compare SNMPv1, v2c and v3 in terms of security
  • you can read snmpget/snmpwalk results and determine interface status and load
  • you can write Python programs that calculate link load from counter values and “walk” along an OID

Plan (according to the syllabus)

  1. SNMP – the network monitoring protocol

An OID is like a station address on a metro map: 1.3.6.1.2.1.1.5.0 — “iso → org → dod → internet → mgmt → mib-2 → system → sysName”. You do not need to memorize the numbers — once you understand the tree, you can read any OID :ik-quti:

Yesterday at 03:12 the connection to the department server was lost. How does the administrator find out in the morning?

A monitoring system (such as Zabbix, PRTG or LibreNMS) asks the switches every minute: “what is the status of your port 24? How many bytes have passed?” And the moment a port goes down, the switch itself sends the message “linkDown!”. All of this happens through a single protocol — SNMP (Simple Network Management Protocol). Today you will learn the instruments of this “network medicine”.

Key terms

Theory reminder

Manager (NMS)listens on UDP 162 Switch (agent) Router (agent) Printer (agent) Get / GetNext / Set → UDP 161 Trap → UDP 162
Fig. 18.1. The manager asks (161), the agents reply and report events on their own (162)
Table 18.1. SNMP operations (PDU types)
OperationDirectionRoleVersion
GetRequestManager → agentRequest the value of a specific OIDv1+
GetNextRequestManager → agentRequest the next OID after the given one and its value — for “walking” along the tree (walk)v1+
GetBulkRequestManager → agentGet many following values in one request (for large tables)v2c+
SetRequestManager → agentChange a value (for example, shut down a port)v1+
ResponseAgent → managerReply to a requestv1+
TrapAgent → managerA message about an event, without confirmationv1+
InformRequestAgent → managerA message that requires a confirmation (Response)v2c+
Table 18.2. SNMP versions
VersionSecurityNote
SNMPv1Community string, in plain text32-bit counters; obsolete
SNMPv2cCommunity string, in plain textGetBulk, Inform, 64-bit counters (Counter64); still widespread today
SNMPv3USM: user, authentication (auth) and encryption (priv)Modes: noAuthNoPriv, authNoPriv, authPriv. The recommended version

SNMP – the network monitoring protocol

Three sample tasks: reading the OID tree, analyzing snmpwalk output and calculating link load from counters.

Sample task 1. The OID tree

All standard management objects are located under 1.3.6.1.2.1 (mib-2). Vendors’ own objects are under 1.3.6.1.4.1 (enterprises) — for example, Cisco’s number is 9.

Table 18.3. The most frequently used OIDs
NameOIDMeaning
sysDescr.01.3.6.1.2.1.1.1.0Device description (model, OS version)
sysUpTime.01.3.6.1.2.1.1.3.0Time since the agent started, in hundredths of a second (TimeTicks)
sysContact.0 / sysName.0 / sysLocation.0…1.1.4.0 / …1.1.5.0 / …1.1.6.0Responsible person, device name, location
ifNumber.01.3.6.1.2.1.2.1.0Number of interfaces
ifDescr.N1.3.6.1.2.1.2.2.1.2.NName of interface N
ifSpeed.N1.3.6.1.2.1.2.2.1.5.NSpeed, bit/s
ifOperStatus.N1.3.6.1.2.1.2.2.1.8.NStatus: 1 — up, 2 — down
ifInOctets.N / ifOutOctets.N…2.2.1.10.N / …2.2.1.16.NBytes received / sent (Counter32)

The trailing .0 is the instance of a scalar (single) object; for table objects the last number is the index (for example, the interface number). Walk along the tree below: click a node — its full OID appears; “GetNext” shows in what order the agent answers.

:ik-xarita: OID tree and GetNext simulator — the department switch

Click a node.

Sample task 2. snmpget and snmpwalk

Commands from the Net-SNMP package (the snmp package on Linux, also available for Windows). The agent on the switch is enabled with the snmp-server community public RO command.

terminal — snmpget / snmpwalk
$ snmpget -v2c -c public 192.168.10.2 SNMPv2-MIB::sysName.0 SNMPv2-MIB::sysUpTime.0
SNMPv2-MIB::sysName.0 = STRING: KAFEDRA-SW1
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (93784512) 10 days, 20:30:45.12

$ snmpwalk -v2c -c public 192.168.10.2 IF-MIB::ifOperStatus
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: down(2)
IF-MIB::ifOperStatus.3 = INTEGER: up(1)

$ snmpwalk -v2c -c public -On 192.168.10.2 1.3.6.1.2.1.2.2.1.10
.1.3.6.1.2.1.2.2.1.10.1 = Counter32: 3456789012
.1.3.6.1.2.1.2.2.1.10.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.10.3 = Counter32: 987654321

$ snmpget -v2c -c notogri 192.168.10.2 sysName.0
Timeout: No Response from 192.168.10.2.
  1. -v2c -c public

    The version and the community string. An agent does not reply at all to a wrong community — so the error appears as a “Timeout” (the last example).

  2. Output format

    MIB-NAME::object.index = TYPE: value. The -On option shows the numeric OID.

  3. Timeticks

    93784512 hundredths of a second = 937845.12 s = 10 days 20 hours 30 minutes 45.12 seconds. A small sysUpTime means the device was restarted recently!

  4. Interface status

    ifOperStatus.2 = down(2) → the matching ifDescr.2 = Gi0/2 for index 2 — that port is not working.

Sample task 3. From a counter to link load

SNMP does not give a “speed” — it gives only a byte counter that keeps growing. The monitoring system reads it twice and divides the difference by the time:

Formula

Load (%) = (Δ bytes × 8) / (Δ time, s × ifSpeed) × 100. If the second value is smaller than the first, Counter32 has wrapped: Δ = second + 232 − first.

Example: Gi0/1 (1 Gbit/s), over a 300-second interval ifInOctets grew from 3,456,789,012 to 3,494,289,012. Δ = 37,500,000 bytes = 300,000,000 bits; in 300 s that is 1,000,000 bit/s = 1 Mbit/s; load = 0.1%.

Warning

The maximum of Counter32 is 4,294,967,295. If a 1 Gbit/s link is fully loaded, it wraps about every 34 seconds — several times within a 5-minute polling interval! That is why 64-bit ifHCInOctets (IF-MIB, ifXTable) in v2c/v3 is used for fast interfaces.

Traps: the device reports on its own

Table 18.4. Standard traps
TrapWhen
coldStart / warmStartThe agent restarted (power cycle / software reload)
linkDown / linkUpAn interface went down / came up
authenticationFailureA request arrived with a wrong community — someone is “guessing the password”
Cisco IOS — configuring an SNMP agentSwitch(config)# snmp-server community public RO 10      ! read-only, restricted by ACL 10
Switch(config)# snmp-server location 3-bino, 214-xona
Switch(config)# snmp-server contact admin@adu.uz
Switch(config)# snmp-server host 192.168.10.50 version 2c public   ! trap receiver
Switch(config)# snmp-server enable traps snmp linkdown linkup
! SNMPv3 (recommended):
Switch(config)# snmp-server group MONITOR v3 priv
Switch(config)# snmp-server user nms MONITOR v3 auth sha AuthParol2026 priv aes 128 PrivParol2026

Test runs: first predict, then check

Independent tasks

7 tasks — you write the “brain” of a monitoring system yourself. Use input() without a prompt.

Common mistakes

ErrorConsequenceCorrect answer
Leaving the default public/private communityA stranger reads everything about the device and, with RW, changes the configurationA complex community + ACL, better still SNMPv3 authPriv
Sorting OIDs as text“…10.10” comes before “…10.2” — the walk order breaksCompare after converting to a tuple of numbers
Ignoring the Counter32 wrapNegative or huge “jumps” on the graphThe wrap formula or 64-bit ifHC* counters
Opening only 161 in the firewallRequests work, traps do not arriveUDP 162 must be open on the manager side too
Thinking a timeout is only a network errorA wrong community goes undetected for a long timePing → UDP 161 → community → version: check one after another
Polling too fast (every second, thousands of OIDs)The device’s processor gets overloadedUsually an interval of 1–5 minutes, GetBulk

Boss level

Boss level: your own snmpwalk

The agent’s MIB: the number of objects n, then n lines “OID TYPE value” (the value may contain spaces), unordered. The last line is the OID where the walk starts (the root of the subtree). Using only the GetNext logic, print all objects of the subtree in numerical order as “.OID = TYPE: value”. At the end print “So‘rovlar: K” (So‘rovlar = requests) — the number of GetNext requests sent (the last request, which went outside the subtree or returned endOfMibView, also counts). If the subtree is empty, only “So‘rovlar: 1”. +60 XP

Reinforcement

Review questions

Name the main parts of the SNMP architecture.

The manager (NMS) sends requests and receives traps; the agent is a program in the device; the MIB is the description of the objects; the protocol is UDP 161/162.

What is the difference between a MIB and an OID?

A MIB is a set of objects and their description (a dictionary); an OID is the numeric address of a particular object in the tree.

Explain the difference between Get, GetNext and GetBulk.

Get — the value of a specific OID; GetNext — the next OID and its value (for walk); GetBulk — many following values in one request (v2c+).

What is the difference between Trap and Inform?

Both are initiated by the agent; a Trap is not acknowledged, while an Inform requires a reply (confirmation) from the manager.

Compare SNMPv1, v2c and v3 in terms of security.

v1 and v2c — an open community; v3 — a user-based model with authentication and encryption (authPriv).

How is link load calculated via SNMP?

By reading ifInOctets/ifOutOctets twice: Δ bytes × 8 / Δ time / ifSpeed × 100%; the wrap is taken into account.

What is a Counter32 wrap and how is it avoided?

The counter starts again from 0 after 2³² − 1; it is corrected with the formula or the 64-bit ifHCInOctets is used.

Why is sysUpTime useful in monitoring?

It shows when the device last restarted; a sharp decrease of the value is a sign of a reboot.

Independent work

The independent-study topic in the course syllabus (the closest one): “Packet transmission, network topologies and network performance.” (6 hours) — in this lesson, from the angle of measuring network performance through SNMP monitoring. Complete the practical work for your variant and present the results with a table/graph.

Assessment criteria (individual assignment)
CriterionPoints
The practical work is done, results (screenshots, code) are present2
OIDs, operations and versions are explained correctly1
Performance indicators (load, status, uptime) are calculated and analyzed1
The security aspect is taken into account, the write-up is orderly1

Summary

SNMPManager ↔ agent; requests on UDP 161, traps on UDP 162.
MIB and OIDA dictionary of objects and their numeric address in the tree; mib-2 = 1.3.6.1.2.1.
OperationsGet, GetNext, GetBulk, Set, Response, Trap, Inform.
WalkA chain of GetNext requests; OIDs are ordered numerically.
LoadΔ bytes × 8 / Δ t / ifSpeed; for a Counter32 wrap — ifHC* counters.
Versionsv1/v2c — an open community; v3 authPriv — recommended.
Practicesnmpget, snmpwalk, sysUpTime, ifOperStatus — indicators of the network’s “health”.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes