LinuxCommandLibrary

snmpset

Set values of SNMP-manageable variables

TLDR

Set a value

$ snmpset -v [version] -c [community] [ip] [oid] [value_type] [value]
copy

Display help
$ snmpset [[-h|--help]]
copy

SYNOPSIS

snmpset [COMMON OPTIONS] AGENT [OID TYPE VALUE]...

COMMON OPTIONS refers to the standard command-line options available across Net-SNMP utilities for specifying SNMP version, security credentials, transport details, and MIB handling.
AGENT is the hostname or IP address of the SNMP agent, optionally followed by a port number (e.g., udp:localhost:161).
OID is the Object Identifier of the variable to set (e.g., sysName.0 or .1.3.6.1.2.1.1.5.0).
TYPE specifies the data type of the value being set. This is crucial and must match the MIB definition for the OID. See "Data Types" below for common types.
VALUE is the new value to which the specified OID will be set.
Multiple OID TYPE VALUE triplets can be provided in a single command to perform multiple modifications within one SNMP SET PDU.

PARAMETERS

-v <1|2c|3>
    Specifies the SNMP protocol version to use.

-c
    Sets the community string for SNMPv1 or SNMPv2c requests.

-u
    Sets the security name (user name) for SNMPv3 requests.

-l
    Sets the security level for SNMPv3 requests (noAuthNoPriv, authNoPriv, authPriv).

-a
    Sets the authentication protocol for SNMPv3 (MD5, SHA).

-A
    Sets the authentication passphrase for SNMPv3.

-x
    Sets the privacy protocol for SNMPv3 (DES, AES, AES192, AES256).

-X
    Sets the privacy passphrase for SNMPv3.

-n
    Sets the context name for SNMPv3 requests.

-t
    Specifies the timeout in seconds before retransmitting a request.

-r
    Specifies the number of retries before giving up.

-M
    Specifies a colon-separated list of directories to search for MIB files.

-m
    Specifies a colon-separated list of MIB modules to load. Use ALL to load all MIBs.

-O
    Specifies various output formatting options (e.g., -Ov for value only).

-P
    Specifies the transport protocols to use (e.g., UDP, TCP).

-d
    Dumps debugging information about the packet exchanges.

OID
    The Object Identifier (MIB variable) to set. Can be numeric or textual.

TYPE
    The data type of the value being set. (e.g., 'i', 's', 'x', 'o', 't', 'a').

VALUE
    The new value to assign to the specified OID.

DESCRIPTION

The snmpset command is a powerful utility from the Net-SNMP suite used to send an SNMP SET request to an SNMP agent. Its primary function is to modify the value of one or more variables (Object Identifiers or OIDs) on a remote SNMP-enabled device. This allows administrators to configure network devices, change system parameters, or control specific functionalities remotely, provided the SNMP agent is configured to permit write operations. Unlike snmpget which retrieves data, snmpset actively changes it. It supports SNMP versions 1, 2c, and 3, offering various security and authentication options for secure operations. The command requires the target agent's address, appropriate credentials (community string for v1/v2c or user/authentication/privacy details for v3), and the specific OID, data type, and new value for each variable to be set.

CAVEATS

Setting SNMP variables requires that the SNMP agent on the target device is configured to allow write operations from the source. Misconfigured SET requests (e.g., incorrect OID, wrong data type, or invalid value) can lead to errors or unexpected behavior on the target device. Always verify the OID's write capability and expected data type from the MIB definition. SNMPv1 and SNMPv2c send community strings in plain text, which is insecure for sensitive operations. SNMPv3 should be used for operations requiring authentication and privacy.

DATA TYPES

The TYPE argument is crucial for snmpset to correctly interpret the VALUE. Common types include:
i: INTEGER or Counter (e.g., 123)
u: UNSIGNED INTEGER or Gauge (e.g., 456U)
s: STRING (e.g., "hello world")
x: HEX STRING (e.g., "0F:A4:B3" or "0xA4B3")
d: DECIMAL STRING (e.g., "10.20.30.40")
n: NULL (e.g., "" for empty)
o: OBJID (e.g., .1.3.6.1.2.1.1.1.0)
t: TIMETICKS (e.g., 360000 for 1 hour)
a: IPADDRESS (e.g., 192.168.1.1)
b: BITS (e.g., "00101100" or "0:1,1:0,2:1")
U: Unaligned string for historical purposes, similar to 's'.
Refer to the MIB definition for the exact type expected for each OID.

EXAMPLES

1. Set system name (SNMPv2c):
snmpset -v 2c -c private localhost sysName.0 s "MyRouter"

2. Set system contact (SNMPv3 with authentication and privacy):
snmpset -v 3 -u myuser -l authPriv -a SHA -A authpass123 -x AES -X privpass456 localhost sysContact.0 s "IT Department <it@example.com>"

3. Set an integer value (e.g., for a custom counter):
snmpset -v 2c -c private localhost .1.3.6.1.4.1.9999.1.1.0 i 12345

4. Set multiple values in one request:
snmpset -v 2c -c private localhost sysName.0 s "NewDevice" sysLocation.0 s "Server Room 1"

HISTORY

snmpset is an integral part of the Net-SNMP project, an open-source suite of SNMP applications and libraries. Initially known as UCD-SNMP, the project has been under continuous development since the mid-1990s. The command has evolved to support all major SNMP versions (v1, v2c, and v3) as they were standardized, incorporating the necessary security and authentication mechanisms. It has become a standard tool for network administrators and developers for automating network device configuration and management tasks.

SEE ALSO

snmpget(1), snmpwalk(1), snmptrap(1), snmpd(8), mib(5)

Copied to clipboard