SkillPilotAI

SNMP: snmpwalk, snmpget, snmpset, snmpbulkwalk, snmptable, snmptranslate, snmptrap (1/2)

Part 1 of the Net-SNMP command-line tools: the common options every command shares (version, community, timeouts, SNMPv3 login, transports, output/input/parsing/logging) and the first three tools, snmpget, snmpwalk and snmpset, run against a real lab agent.

269.1 Why is it used?

  • SNMP is the standard protocol to monitor routers, switches and servers; Net-SNMP tools are how you talk to it from a shell.
  • Read values (snmpget), whole subtrees (snmpwalk) or change writable values (snmpset).
  • Linux: package snmp (Debian/Ubuntu) or net-snmp-utils (Fedora); macOS built in or brew; Windows: Net-SNMP build or WSL.

269.2 How it works

Manager and agent on UDP 161
  1. 1.NMS n269-nms (192.168.69.20) runs snmpget

  2. 2.GET request goes to UDP 161 through the switch

  3. 3.snmpd on router1 (192.168.69.10) checks community/user and view

  4. 4.Agent reads the OID value from its MIB (sysName.0)

  5. 5.Response returns; a wrong community is dropped silently -> Timeout

CredentialAccess in the lab
labview (v2c)Read-only, whole subnet 192.168.69.0/24
labwrite (v2c)Write only from the NMS IP, only sysContact and sysLocation
asha (v3)Needs SHA auth + AES privacy (authPriv)
Wrong communityDropped with no reply -> Timeout

269.3 Generic and v1/v2c options

OptionMeaning
-v 1|2c|3SNMP version
-c COMMCommunity (v1/v2c)
-r N / -t SECRetries (default 5) / timeout (default 1)
-dHex dump of raw packets
-D TOKENDebug output (-DALL)
-m / -MWhich MIBs / MIB directories
-Yname=value, --name=valueSet snmp.conf tokens on the command line
-h / -H / -VHelp / config directives / version
Terminal
snmpget -v 2c -c labview 192.168.69.10 sysName.0 sysLocation.0 sysUpTime.0time snmpget -v 2c -c wrongpass -t 1 -r 0 192.168.69.10 sysName.0time snmpget -v 2c -c wrongpass -t 1 -r 2 192.168.69.10 sysName.0
Output
Timeout: No Response from 192.168.69.10.real	0m 1.06sTimeout: No Response from 192.168.69.10.real	0m 3.06s
  • -t 1 -r 0 = one try, timeout after 1 s; -r 2 = three tries, error after 3 s.
  • -d shows 'labview' readable in the ASCII column: v1/v2c communities travel in plain text.
Terminal
snmpget -v 2c -c labview -d 192.168.69.10 sysName.0snmpget -v 2c -Ydefcommunity=labview 192.168.69.10 sysName.0snmpget --defVersion=2c --defCommunity=labview 192.168.69.10 sysName.0
Output
Sending 44 bytes to UDP: [192.168.69.10]:161->[0.0.0.0]:580140000: 30 2A 02 01  01 04 07 6C  61 62 76 69  65 77 A0 1C    0*.....labview.....SNMPv2-MIB::sysName.0 = STRING: router1

269.4 SNMPv3 and TLS/DTLS options

  • -l noAuthNoPriv | authNoPriv | authPriv sets the security level; -u is the user.
  • -a MD5|SHA|SHA-224..SHA-512 (auth), -x DES|AES (privacy); -A/-X passphrases end up in shell history, so the lab kept them in /root/.snmp/snmp.conf.
  • -3m/-3M/-3k/-3K give ready keys; -e/-E engine IDs; -n context name; -Z engineBoots,engineTime.
  • TLS/DTLS: -T localCert, peerCert, trust_cert, their_hostname with tls:/dtls: transports (certificates instead of passphrases; syntax only).
Terminal
snmpget -v 3 -l authPriv -u asha -a SHA -x AES 192.168.69.10 sysName.0 sysLocation.0snmpget -v 3 -l noAuthNoPriv -u asha 192.168.69.10 sysName.0snmpget -v 3 -l authPriv -u ravi -a SHA -x AES 192.168.69.10 sysName.0
Output
[nms]$ snmpget -v 3 -l noAuthNoPriv -u asha 192.168.69.10 sysName.0Error in packetReason: authorizationError (access denied to that object)[nms]$ snmpget -v 3 -l authPriv -u ravi -a SHA -x AES 192.168.69.10 sysName.0snmpget: Unknown user name (Sub-id not found: (top) -> sysName)

269.5 Agent specification (transport)

  • A bare IP means UDP 161; udp:IP:161 says the same explicitly; tcp:, udp6:, tcp6: for TCP and IPv6.
  • tls:, dtls:, ssh: use the TSM model of SNMPv3; unix:/path for a local agent; alias:NAME from snmp.conf; ipx:, aal5pvc: are rare.
Terminal
snmpget -v 2c -c labview udp:192.168.69.10:161 sysName.0snmpget -v 2c -c labview tcp:192.168.69.10:161 sysName.0snmpget -v 2c -c labview -t 1 -r 0 udp:192.168.69.10:1161 sysName.0
Output
SNMPv2-MIB::sysName.0 = STRING: router1SNMPv2-MIB::sysName.0 = STRING: router1Timeout: No Response from udp:192.168.69.10:1161.

269.6 Output, input, MIB parsing and logging options

OptionEffect
-On / -OfNumeric OID / full path iso.org.dod.internet...
-Os / -OSShort name / MIB::name
-Oq / -OvNo '=' and type / value only (best for scripts)
-Ot / -OeRaw TimeTicks / enum as number (up -> 1)
-Ox / -Oa / -OTStrings as hex / ASCII / hex + printable
-Ir / -Is SUF / -IbSkip MIB index check / add suffix / regex lookup
-Pw / -Pd / -PeParse warnings / skip descriptions / show MIB errors
-Le / -Lo / -Lf / -Ls / -LnLog to stderr / stdout / file / syslog / off
Terminal
snmpget -v 2c -c labview -Os 192.168.69.10 sysUpTime.0 sysName.0 IF-MIB::ifAdminStatus.1snmpget -v 2c -c labview -Ot 192.168.69.10 sysUpTime.0 sysName.0 IF-MIB::ifAdminStatus.1
Output
sysUpTimeInstance = Timeticks: (4062) 0:00:40.62sysName.0 = STRING: router1ifAdminStatus.1 = INTEGER: up(1) DISMAN-EVENT-MIB::sysUpTimeInstance = 4731SNMPv2-MIB::sysName.0 = STRING: router1IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
  • ifDescr.0 is rejected by the client ('Index out of range', ifIndex starts at 1); with -Ir it reaches the agent, which says No Such Instance.
  • -Is .1 fetched three values of interface 1 in one command; -m ALL -Pw -Lf wrote 11 warning lines to a file.
Terminal
snmpget -v 2c -c labview -Is .1 192.168.69.10 IF-MIB::ifDescr IF-MIB::ifMtu IF-MIB::ifOperStatus
Output
IF-MIB::ifDescr.1 = STRING: loIF-MIB::ifMtu.1 = INTEGER: 65536IF-MIB::ifOperStatus.1 = INTEGER: up(1)

269.7 snmpget and snmpwalk

  • snmpget needs the instance of every OID (.0); in v1 a bad OID (sysContact without .0) gives noSuchName, snmpget drops it and retries; -Cf turns the fix-and-retry off.
  • snmpwalk runs GETNEXT over a subtree (no OID = whole mib-2).
  • -Cp count, -Ct time, -CE OID stop point, -Ci include the given OID, -CI skip final GET, -Cc no order check.
Terminal
snmpget -v 1 -c labview 192.168.69.10 sysName.0 sysContactsnmpwalk -v 2c -c labview -Cp -Ct 192.168.69.10 IF-MIB::ifDescrsnmpwalk -v 2c -c labview -Os -CE sysORTable 192.168.69.10 system
Output
IF-MIB::ifDescr.1 = STRING: loTotal traversal time = 0.007302 secondsIF-MIB::ifDescr.3 = STRING: eth1Variables found: 2 sysObjectID.0 = OID: netSnmpAgentOIDs.10sysUpTimeInstance = Timeticks: (8803) 0:01:28.03sysContact.0 = STRING: root@unknownsysName.0 = STRING: router1sysLocation.0 = STRING: SiteA rack 2sysORLastChange.0 = Timeticks: (0) 0:00:00.00

269.8 snmpset

  • Format: AGENT OID TYPE VALUE; types i, u, s, x, d, n, o, t, a, b, and = (type taken from the MIB).
  • labwrite changed sysContact; sysLocation fixed in snmpd.conf -> notWritable; sysName outside the view -> noAccess; read-only labview -> noAccess.
  • Wrong type (i for a string) is caught by the client: Bad variable type.
Terminal
snmpset -v 2c -c labwrite 192.168.69.10 sysContact.0 s asha@lab.localsnmpset -v 2c -c labwrite 192.168.69.10 sysName.0 s core1snmpset -v 2c -c labwrite 192.168.69.10 sysContact.0 i 5snmpset -v 2c -c labwrite 192.168.69.10 sysContact.0 x '61 73 68 61'
Output
Error in packet.Reason: noAccessFailed object: SNMPv2-MIB::sysName.0sysContact.0: Bad variable type (Type of attribute is OCTET STRING, not INTEGER)SNMPv2-MIB::sysContact.0 = STRING: asha

269.9 Common mistakes

  • Treating the community as a password: -d shows it in plain text; use v3 authPriv for writes and keep v2c read-only and IP-limited.
  • Reading a Timeout as 'device down': wrong community, IP not allowed, wrong version or blocked UDP 161 all look the same.
  • Forgetting .0 on scalar OIDs in snmpget.
  • Typing -A/-X passphrases on the command line (saved in history).

269.10 Interview tips

  • v2c = plain-text community, no login, no encryption; v3 = USM user, authPriv gives SHA auth + AES encryption.
  • Timeout from snmpget: check community, allowed IP, version and UDP 161 on the firewall.
  • -Ov / -Oq are the script-friendly output options.
  • snmpset needs write access, a writable object inside the view and the correct type.