a black and white cubes on a black background
Wed Dec 20

Configuring SNMPv3 in Linux

SNMP, or Simple Network Management Protocol, is a widely used protocol for monitoring and managing network devices. SNMP allows network administrators to collect information about the status, performance, and configuration of various network components, such as routers, switches, servers, printers, etc.

SNMP has three versions: SNMPv1, SNMPv2c, and SNMPv3. SNMPv1 is the original version that was released in 1988. It is simple and easy to use, but it has some limitations and security issues. SNMPv2c is an extension of SNMPv1 that adds some new features and improvements, such as bulk data transfer and error handling. However, SNMPv2c still uses plain text community strings for authentication, which can be easily intercepted and spoofed by attackers.

SNMPv3 is the latest and most secure version of SNMP. It was released in 1998 and it provides several enhancements over the previous versions, such as:

  • User-based security model (USM), which allows the creation of multiple users with different levels of access and privileges
  • Message integrity, which ensures that the SNMP messages are not tampered with during transmission
  • Encryption, which protects the SNMP messages from being read by unauthorized parties
  • View-based access control model (VACM), which allows the definition of access policies for different users and groups

In this article, we will show you how to configure SNMPv3 on Linux, using CentOS 7 as an example. We will also show you how to test the SNMPv3 configuration and verify its security features. By the end of this article, you will be able to enable SNMPv3 on your Linux system and use it for network management.

How to Install SNMP Packages on Linux

Before we can configure SNMPv3 on Linux, we need to install some packages that are required for SNMP functionality. The main package is net-snmp, which provides the SNMP agent and the SNMP utilities. The net-snmp-utils package contains some additional tools that are useful for SNMP testing and troubleshooting.

To install these packages on CentOS 7, we can use the yum command as follows:

sudo yum install net-snmp net-snmp-utils

To install these packages on Ubuntu 18.04, we can use the apt-get command as follows:

sudo apt-get update
sudo apt-get install snmp snmpd snmp-mibs-downloader

After installing the packages, we need to enable and start the SNMP daemon, which is called snmpd. The snmpd service is responsible for listening to SNMP requests and providing SNMP information to the clients.

To enable and start the snmpd service on CentOS 7, we can use the systemctl command as follows:

sudo systemctl enable snmpd
sudo systemctl start snmpd

To enable and start the snmpd service on Ubuntu 18.04, we can use the same command as follows:

sudo systemctl enable snmpd
sudo systemctl start snmpd

How to Create SNMPv3 User on Linux

Now that we have installed and started the SNMP daemon, we need to create an SNMPv3 user that will be used to access the SNMP agent. The SNMPv3 user will have a username, an authentication password, an authentication algorithm, an encryption password, and an encryption algorithm. The authentication password and algorithm are used to verify the identity of the user, while the encryption password and algorithm are used to encrypt the SNMP messages.

To create an SNMPv3 user on Linux, we can use the net-snmp-create-v3-user command, which is a script that automates the process of editing the snmpd configuration file. The snmpd configuration file is located at /etc/snmp/snmpd.conf on both CentOS 7 and Ubuntu 18.04.

Before we run the net-snmp-create-v3-user command, we need to stop the snmpd service, as the script will overwrite the existing configuration file. To stop the snmpd service, we can use the systemctl command as follows:

sudo systemctl stop snmpd

Then, we can run the net-snmp-create-v3-user command with the following syntax:

sudo net-snmp-create-v3-user [-ro] [-A authpass] [-a MD5|SHA] [-X privpass] [-x DES|AES] username

The options are as follows:

  • -ro: This option makes the user read-only, meaning that the user can only query the SNMP agent, but not modify it. If this option is omitted, the user will have read-write access, which is not recommended for security reasons.
  • -A authpass: This option specifies the authentication password for the user. The password should be at least 8 characters long and should not contain any special characters.
  • -a MD5|SHA: This option specifies the authentication algorithm for the user. The algorithm can be either MD5 or SHA. The default is MD5.
  • -X privpass: This option specifies the encryption password for the user. The password should be at least 8 characters long and should not contain any special characters.
  • -x DES|AES: This option specifies the encryption algorithm for the user. The algorithm can be either DES or AES. The default is DES.
  • username: This is the name of the user that will be created.

For example, to create a read-only SNMPv3 user named snmpuser with the authentication password snmpauth, the authentication algorithm SHA, the encryption password snmppriv, and the encryption algorithm AES, we can run the following command:

sudo net-snmp-create-v3-user -ro -A snmpauth -a SHA -X snmppriv -x AES snmpuser

The net-snmp-create-v3-user command will generate a new snmpd configuration file with the following lines:

createUser snmpuser SHA "snmpauth" AES "snmppriv"
rouser snmpuser

The createUser directive defines the SNMPv3 user with the specified parameters. The rouser directive grants read-only access to the user.

After running the net-snmp-create-v3-user command, we need to start the snmpd service again, as the script will reload the new configuration file. To start the snmpd service, we can use the systemctl command as follows:

sudo systemctl start snmpd

How to Test SNMPv3 Configuration on Linux

Now that we have created an SNMPv3 user on Linux, we can test the SNMPv3 configuration and verify its security features. To test the SNMPv3 configuration, we can use the snmpwalk command, which is a tool that performs a series of SNMP get-next requests and displays the results in a human- readable format. The snmpwalk command is part of the net-snmp-utils package that we installed earlier.

To use the snmpwalk command with SNMPv3, we need to specify the following options:

  • -v 3: This option indicates that we are using SNMPv3 protocol.
  • -u username: This option specifies the SNMPv3 user that we created earlier.
  • -l authPriv: This option indicates that we are using both authentication and encryption for SNMPv3.
  • -a MD5|SHA: This option specifies the authentication algorithm that we used for the SNMPv3 user.
  • -A authpass: This option specifies the authentication password that we used for the SNMPv3 user.
  • -x DES|AES: This option specifies the encryption algorithm that we used for the SNMPv3 user.
  • -X privpass: This option specifies the encryption password that we used for the SNMPv3 user.
  • hostname: This is the name or IP address of the SNMP agent that we want to query.
  • OID: This is the object identifier that we want to query. An OID is a unique identifier that represents a specific variable in the SNMP MIB (Management Information Base). The MIB is a hierarchical database that defines the structure and attributes of the SNMP data.

For example, to query the system information of the SNMP agent using the SNMPv3 user that we created earlier, we can run the following command:

snmpwalk -v 3 -u snmpuser -l authPriv -a SHA -A snmpauth -x AES -X snmppriv localhost .1.3.6.1.2.1.1

The OID .1.3.6.1.2.1.1 corresponds to the system group in the SNMP MIB, which contains information such as the system name, description, uptime, contact, location, etc.

The output of the snmpwalk command will look something like this:

    SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64
    SNMPv2-MIB::sysObjectID.0 = OID:
    NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (123456) 0:20:34.56 SNMPv2-MIB::sysContact.0 = STRING: Root root@localhost
    SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
    SNMPv2-MIB::sysLocation.0 = STRING: Unknown
    SNMPv2-MIB::sysServices.0 = INTEGER: 72

The output provides information about the system description, object ID, uptime, contact, name, location, and services available on the SNMP agent.

This demonstrates that our SNMPv3 configuration is working, and we can successfully query the SNMP agent using the configured SNMPv3 user credentials. Additionally, the authentication and encryption mechanisms are ensuring the security and integrity of the communication between the SNMP manager and the agent.

Conclusion

In conclusion, SNMPv3 is a highly secure and robust protocol for network management. Its enhanced security features, such as user-based security, message integrity, and encryption, make it the preferred choice over SNMPv1 and SNMPv2c. Configuring SNMPv3 on Linux involves installing the necessary packages, creating an SNMPv3 user with appropriate security parameters, and testing the configuration to ensure proper functionality.

By following the step-by-step guide provided in this article, you can easily set up SNMPv3 on your Linux system and utilize its capabilities for effective network monitoring and management. Remember to adhere to best practices in security, such as using strong passwords and regularly updating configurations, to maintain a secure network environment.