SNMP and network monitoring
SNMP (Simple Network Management Protocol) lets one central server read the health and traffic numbers of every router, switch and server, and lets devices raise alerts themselves. It is the base of almost every network monitoring tool.
266.1 Why is it used?
- With 50 switches and routers you cannot log in to each one to find a full link; it takes hours.
- Meanwhile a Site B router can go down and nobody notices.
- SNMP collects the numbers of all devices from one place (polling) and devices push events (traps).
266.2 How it works: NMS and agent
- NMS (Network Management Station) = the central manager; agent = small program on every device.
- GET: NMS asks for one value on UDP 161, the agent replies.
- WALK: repeated GETNEXT requests ('give me the next value after this OID') until the subtree is complete.
- TRAP: the device itself sends an event to the NMS on UDP 162; no reply. INFORM is the acknowledged version.
- Step 1
1.NMS 192.168.66.20 sends GET sysName.0 to UDP 161
- Step 2
2.Packet crosses the switch to router1 (192.168.66.10)
- Step 3
3.Agent on router1 reads its value
- Step 4
4.Reply: sysName.0 = router1
- Step 1
1.router1's Site B link goes down
- Step 2
2.router1 sends a linkDown trap to NMS UDP 162
- Step 3
3.snmptrapd on the NMS receives and logs it
- Step 4
4.Alert shows up immediately, no waiting for the next poll
| Operation | Direction | Port | Use |
|---|---|---|---|
| GET | NMS -> agent | UDP 161 | One value |
| GETNEXT / WALK | NMS -> agent | UDP 161 | A whole subtree |
| GETBULK (v2c+) | NMS -> agent | UDP 161 | Many values per request |
| SET | NMS -> agent | UDP 161 | Change a value |
| TRAP / INFORM | agent -> NMS | UDP 162 | Event alert (INFORM is acknowledged) |
266.3 MIB and OID
- Every value has a unique address, the OID (Object Identifier), and OIDs form a tree.
- Path: iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1).sysName(5); the trailing .0 means a single instance.
- The MIB (Management Information Base) is a dictionary file that gives OID numbers a name and a type.
- interfaces(2) holds ifDescr and ifOperStatus (IF-MIB).
Output
iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) system(1) sysDescr(1) sysUpTime(3) sysName(5) .0 = instance sysLocation(6) interfaces(2) ifDescr, ifOperStatus sysName.0 = 1.3.6.1.2.1.1.5.0Terminal
snmptranslate -On SNMPv2-MIB::sysName.0snmptranslate .1.3.6.1.2.1.1.5.0Output
$ snmptranslate -On SNMPv2-MIB::sysName.0.1.3.6.1.2.1.1.5.0$ snmptranslate .1.3.6.1.2.1.1.5.0SNMPv2-MIB::sysName.0266.4 Comparison: SNMP v1 vs v2c vs v3
| Point | v1 | v2c | v3 |
|---|---|---|---|
| Authentication | Community string | Community string | User (USM) with SHA auth |
| Encryption | None, plain text | None, plain text | Privacy (AES) |
| Extras | Old | GETBULK, 64-bit counters | authPriv levels, VACM views |
| Status | Old | Common | Secure |
- Many devices ship with public (read) and private (write) as default communities: always change them.
266.5 Lab: snmpd on router1
- Closed Docker lab 192.168.66.0/24: router1 = .10 (agent), nms = .20.
- Read-only v2c community labview allowed only from the lab subnet; v3 user asha with SHA + AES (rouser asha priv).
Output
agentAddress udp:192.168.66.10:161sysName router1sysDescr Lab router1 (net-snmp agent)sysLocation SiteA rack 2sysContact noc@lab.localrocommunity labview 192.168.66.0/24createUser asha SHA "*****" AES "*****"rouser asha privTerminal
snmpget -v2c -c labview 192.168.66.10 sysName.0 sysUpTime.0snmpget -v2c -c labview -On 192.168.66.10 1.3.6.1.2.1.1.5.0snmpwalk -v2c -c labview 192.168.66.10 systemOutput
$ snmpwalk -v2c -c labview 192.168.66.10 systemSNMPv2-MIB::sysDescr.0 = STRING: Lab router1 (net-snmp agent)SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2292) 0:00:22.92SNMPv2-MIB::sysContact.0 = STRING: noc@lab.localSNMPv2-MIB::sysName.0 = STRING: router1SNMPv2-MIB::sysLocation.0 = STRING: SiteA rack 2Terminal
snmpwalk -v2c -c labview 192.168.66.10 IF-MIB::ifDescrsnmpwalk -v2c -c labview 192.168.66.10 IF-MIB::ifOperStatusOutput
IF-MIB::ifDescr.1 = STRING: loIF-MIB::ifDescr.3 = STRING: eth0IF-MIB::ifOperStatus.1 = INTEGER: up(1)IF-MIB::ifOperStatus.3 = INTEGER: up(1)- v3 authPriv (SHA + AES) returns router1 and SiteA rack 2; the same user with noAuthNoPriv gets authorizationError.
- A wrong community (public) gets no reply at all: only a Timeout, no clear error.
Terminal
snmpget -v3 -l authPriv -u asha -a SHA -A "$AUTH" -x AES -X "$PRIV" 192.168.66.10 sysName.0 sysLocation.0snmpget -v3 -l noAuthNoPriv -u asha 192.168.66.10 sysName.0snmpget -v2c -c public -t 1 -r 1 192.168.66.10 sysName.0Output
$ snmpget -v3 -l noAuthNoPriv -u asha 192.168.66.10 sysName.0Error in packetReason: authorizationError (access denied to that object)$ snmpget -v2c -c public -t 1 -r 1 192.168.66.10 sysName.0Timeout: No Response from 192.168.66.10.Terminal
# on router1 (sent by hand in the lab; a real router sends it itself)snmptrap -v 2c -c labview 192.168.66.20:162 '' IF-MIB::linkDown IF-MIB::ifIndex.2 i 2 IF-MIB::ifAdminStatus.2 i 1 IF-MIB::ifOperStatus.2 i 2# on nms (snmptrapd listens on UDP 162)tr '\t' '\n' < /var/log/snmptrapd.logOutput
2026-11-09 20:33:54 UDP: [192.168.66.10]:34395->[192.168.66.20]:162 [UDP: [192.168.66.10]:34395->[192.168.66.20]:162]:SNMPv2-MIB::snmpTrapOID.0 = OID: IF-MIB::linkDownIF-MIB::ifIndex.2 = INTEGER: 2IF-MIB::ifAdminStatus.2 = INTEGER: up(1)IF-MIB::ifOperStatus.2 = INTEGER: down(2)- tcpdump on router1's interface shows C="labview" in every v2c packet: any sniffer can read the community. Capture only in your own lab.
Terminal
tcpdump -p -n -v -c 4 -i any udp port 161Output
192.168.66.20.33427 > 192.168.66.10.161: { SNMPv2c C="labview" { GetRequest(28) R=695944959 .1.3.6.1.2.1.1.5.0 } } 192.168.66.10.161 > 192.168.66.20.33427: { SNMPv2c C="labview" { GetResponse(35) R=695944959 .1.3.6.1.2.1.1.5.0="router1" } } 4 packets captured266.6 Monitoring tools
- Zabbix, LibreNMS, PRTG, Nagios and Cacti all work on the same idea.
- Polling (GET/WALK) at a fixed interval gives graphs, trends and history.
- Traps on UDP 162 give immediate alerts; good setups use polling and traps together.
266.7 Common mistakes
- Believing the community string is a safe password: in v1/v2c it travels in plain text.
- Leaving the default public/private communities on devices.
- Relying on polling only: a 2-minute outage between 5-minute polls can be missed.
- Reading a Timeout as a network problem when the community is simply wrong.
266.8 Interview tips
- v2c = community string in plain text, no real auth or encryption; v3 = USM user with auth (SHA) + priv (AES) and VACM views.
- Ports: GET/WALK/SET on UDP 161, TRAP/INFORM on UDP 162.
- OID = numeric address of a value; MIB = dictionary that names it (sysName.0 = 1.3.6.1.2.1.1.5.0).
- Polling for trends, traps for instant events: use both.