Difference between revisions of "TUT:snmpset"

From Net-SNMP Wiki
Jump to: navigation, search
 
m (punctuation fixes)
Line 13: Line 13:
  
  
So, lets check, set, and check again the value of a variable using snmpget and snmpset:  
+
So, let's check, set, and check again the value of a variable using snmpget and snmpset:  
  
 
   % '''snmpget -v 2c -c demopublic test.net-snmp.org ucdDemoPublicString.0'''
 
   % '''snmpget -v 2c -c demopublic test.net-snmp.org ucdDemoPublicString.0'''
Line 42: Line 42:
 
SNMPv1 did not have nearly as descriptive error codes, which SNMPv2c
 
SNMPv1 did not have nearly as descriptive error codes, which SNMPv2c
 
fixed. It's a good reason to use SNMPv2c in preference to SNMPv1. Even
 
fixed. It's a good reason to use SNMPv2c in preference to SNMPv1. Even
better, is to use SNMPv3 which has a much better security system and
+
better is to use SNMPv3 which has a much better security system and
 
also uses the better error reporting. We'll talk extensively about
 
also uses the better error reporting. We'll talk extensively about
 
SNMPv3 later.
 
SNMPv3 later.
  
 
{{TUT:LIST}}
 
{{TUT:LIST}}

Revision as of 16:35, 9 March 2007

snmpset

The snmpset command is used to actually modify information on the remote host. For each variable you want to set, you need to specify the OID to update, the data type and the value you want to set it to.

The valid datatypes can be found at the end of the snmpset help output:

 % snmpset -h |& tail -4
   type - one of i, u, t, a, o, s, x, d, n
     i: INTEGER, u: unsigned INTEGER, t: TIMETICKS, a: IPADDRESS
     o: OBJID, s: STRING, x: HEX STRING, d: DECIMAL STRING
     U: unsigned int64, I: signed int64, F: float, D: double


So, let's check, set, and check again the value of a variable using snmpget and snmpset:

 % snmpget -v 2c -c demopublic test.net-snmp.org ucdDemoPublicString.0
 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoPublicString.0 =  "hi there"
 % snmpset -v 2c -c demopublic test.net-snmp.org ucdDemoPublicString.0 s "hello world"
 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoPublicString.0 = "hello world"
 % snmpget -v 2c -c demopublic test.net-snmp.org ucdDemoPublicString.0
 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoPublicString.0
 =  "hello world"

As you can see, we successfully changed the value of the ucdDemoPublicString.0 object.

Note that if you don't have write permission to the object, the errors will differ greatly between SNMPv1 and SNMPv2c:

 % snmpset -v 1 -c badcommunity test.net-snmp.org ucdDemoPublicString.0 s "hello"
 Error in packet.
 Reason: (noSuchName) There is no such variable name in this MIB.
 This name doesn't exist: ucdDemoPublicString.0
 % snmpset -v 2c -c badcommunity test.net-snmp.org ucdDemoPublicString.0 s "hello"
 Error in packet.
 Reason: notWritable


SNMPv1 did not have nearly as descriptive error codes, which SNMPv2c fixed. It's a good reason to use SNMPv2c in preference to SNMPv1. Even better is to use SNMPv3 which has a much better security system and also uses the better error reporting. We'll talk extensively about SNMPv3 later.

Tutorial Sections

About the SNMP Protocol

These tutorial links talk about SNMP generically and how the protocol itself works. They are good introductory reading material and the concepts are important to understand before diving into the later tutorials about Net-SNMP itself.

Net-SNMP Command Line Applications

These tutorial pages discuss the command line tools provided in the Net-SNMP suite of tools. Nearly all the example commands in these tutorials works if you try it yourself, as they're all examples that talk to our online Net-SNMP test agent. Given them a shot!

Application Configuration

All of our applications support configuration to allow you to customize how they behave.

Net-SNMP Daemons

Net-SNMP comes with two long-running daemons: a SNMP agent (snmpd) for responding to management requests and a notification receiver (snmptrapd) for receiving SNMP notifications.

Coding Tutorials

Net-SNMP comes with a highly flexible and extensible API. The API allows you to create your own commands, add extensions to the agent to support your own MIBs and perform specialized processing of notifications.

Debugging SNMP Applications and Agents

All our tools and applications have extensive debugging output. These tutorials talk about how the debugging system works and how you can add your own debugging statements to you code:

Operating System Specific Tutorials