SNMP Version 2 (SNMPv2) Syntax with Detailed Explanation
Simple Network Management Protocol (SNMP) Version 2, commonly referred to as SNMPv2, is an improved version of the original SNMPv1 protocol. SNMP Version 2 provides enhanced features such as improved error handling, bulk retrieval, and expanded data types, while keeping the simplicity of its predecessor.

The basic syntax for SNMP Version 2 is similar to SNMPv1 but with additional functionality like GET-BULK requests and improved response formats.
SNMPv2 Command Overview
Here are the main commands used in SNMPv2:
- snmpget: Retrieves the value of a specific object identifier (OID).
- snmpset: Modifies the value of a specific OID.
- snmpwalk: Retrieves a tree of OIDs.
- snmpbulkget: Retrieves large amounts of data efficiently (new in SNMPv2).
- snmptrap: Sends a trap (notification) to a manager.
- snmpgetnext: Retrieves the next OID in the tree.
SNMPv2 Syntax Structure
- Host: The IP or hostname of the device you’re querying.
- Community: The SNMP community string, typically set as “public” for read-only access or “private” for read-write access.
- OID: Object Identifier that specifies the data you want to interact with.
Basic command structure:
snmp[v2 command] -v 2c -c [community] [host] [OID]Example Commands
1. snmpget (Retrieve a Specific OID Value)
snmpget retrieves the value of a single OID. Here is the syntax:
snmpget -v 2c -c [community] [host] [OID]- -v 2c: Specifies the use of SNMPv2c.
- -c [community]: Community string (e.g., public).
- [host]: The IP or hostname of the target device.
- [OID]: The specific object identifier to query.
Example:
snmpget -v 2c -c public 192.168.1.1 sysName.0This command queries the sysName.0 OID on the device with IP 192.168.1.1 to retrieve the system name.
2. snmpset (Set a Value for a Specific OID)
snmpset is used to modify the value of an OID. The value should match the data type of the OID.
Syntax:
snmpset -v 2c -c [community] [host] [OID] [data type] [value]Data types:
- i: Integer.
- u: Unsigned integer.
- s: String.
- x: Hexadecimal string.
- d: Decimal string.
- a: IP address.
Example:
This command sets the sysLocation.0 OID to the string value “Data Center 1” on the device.
3. snmpwalk (Walk Through a Set of OIDs)
snmpwalk retrieves a subtree of OIDs from the MIB starting from the specified OID.
Syntax:
snmpwalk -v 2c -c [community] [host] [OID]Example:
snmpwalk -v 2c -c public 192.168.1.1 systemThis command walks through all OIDs under the system branch starting from 1.3.6.1.2.1.1 on the device.
4. snmpbulkget (Bulk Retrieval of Data)
SNMP Version 2 introduced snmpbulkget, which allows you to retrieve large amounts of data in fewer packets. It reduces network load when pulling multiple OIDs.
Syntax:
snmpbulkget -v 2c -c [community] [host] [nonrepeaters] [maxrepetitions] [OID]- nonrepeaters: Number of OIDs that should be fetched using GETNEXT.
- maxrepetitions: The number of OIDs to retrieve after the first nonrepeaters objects.
Example:
snmpbulkget -v 2c -c public 192.168.1.1 1 10 ifTableThis command retrieves 10 rows from the ifTable starting from the specified OID.
5. snmptrap (Send SNMP Trap)
SNMP traps are notifications sent from agents to managers, typically used for alerting purposes.
Syntax:
snmptrap -v 2c -c [community] [host] [OID] [value]Example:
snmptrap -v 2c -c public 192.168.1.1 '' .1.3.6.1.4.1.8072.2.3.0.1 sysUpTime.0 t 0This command sends a trap to the SNMP manager at IP 192.168.1.1.
6. snmpgetnext (Get the Next OID in a Tree)
snmpgetnext retrieves the next OID in a list from the specified OID.
Syntax:
snmpgetnext -v 2c -c [community] [host] [OID]Example:
snmpgetnext -v 2c -c public 192.168.1.1 sysUpTime.0This command retrieves the OID that follows sysUpTime.0.
Practical Examples of SNMPv2c Commands
Example 1: Checking System Uptime
To retrieve the system uptime of a network device:
snmpget -v 2c -c public 192.168.1.1 sysUpTime.0Example 2: Walking the Interface Table
To walk through the interface table (ifTable) on a device:
snmpwalk -v 2c -c public 192.168.1.1 ifTableExample 3: Setting System Contact Information
To set the system contact info on a device:
Example 4: Bulk Fetching Interface Data
To retrieve multiple interface entries in one bulk request:
snmpbulkget -v 2c -c public 192.168.1.1 0 5 ifTableAdvantages of SNMPv2
- Bulk Operations: snmpbulkget allows retrieving large amounts of data with fewer requests, reducing network overhead.
- Improved Error Handling: SNMP Version 2 provides better error reporting than SNMPv1.
- Expanded Data Types: SNMP Version 2 supports a wider range of data types for more flexible management.
Disadvantages of SNMPv2
- Security: SNMPv2c uses community strings for security, which is considered weak because the strings are transmitted in plain text.
- Compatibility: While SNMP Version 2 offers more features, some older devices may not fully support it, requiring SNMPv1 for backward compatibility.
Summary
SNMP Version 2 is an upgrade to SNMPv1, offering bulk data retrieval, improved error handling, and more data types. While it brings some advantages, security remains a concern in the community-based version (SNMPv2c). SNMPv3 addresses these security concerns with features like encryption and authentication.
Useful Links
Comprehensive SNMPv2 Syntax: Commands, Examples, and Usage
This article provided insights on the topic. For latest updates and detailed guides, stay connected with Sanchit Gurukul.
Your feedback matters
Was this post helpful?
Discussion
0 approved comments
No approved comments yet. You can start the discussion below.
Leave a Comment
No login is required. Name and email are used for moderation/security. Your email is never displayed publicly. All comments require administrator approval.
Discover more from SanchitGurukul
Subscribe to get the latest posts sent to your email.