SNMP stands for Simple Network Management Protocol. It is a protocol to fetch system statistics. The target machine is called “Agent” and the monitoring machine is called “NMS(Network management system)” or you can just call it “Manager”.
SNMP is a protocol used for managing and monitoring network devices and their functions. SNMPd refers to the SNMP daemon or service that runs on a network device, allowing it to respond to SNMP queries and notifications.
SNMP Agent Configuration
Most devices like VMs, routers, switches, etc have an SNMP daemon/agent configuration pre-installed. If it is not then do below.
# Install snmpd service
sudo yum install net-snmp
# snmpd commands
sudo systemctl start snmpd
sudo systemctl enable snmpd
systemctl status snmpd
sudo systemctl restart snmpd
sudo systemctl stop snmpd
You have to create a user account in the SNMP agent to use the service. It takes two passwords, a username and algorithms to encrypt the credentials. Here is how you can create a user.
# first you have to stop the snmpd
sudo systemctl stop snmpd
# create the usernet-snmp-create-v3-user -ro -A snmpv3authPass -a SHA -X snmpv3encPass -x AES snmpv3user
# This will print something like this:
adding the following line to /var/lib/net-snmp/snmpd.conf:
createUser snmpv3user SHA "snmpv3authPass" AES snmpv3encPass
adding the following line to /etc/snmp/snmpd.conf:
rouser snmpv3user
# start snmpd
sudo systemctl start snmpd
Here -ro indicate read-only. For read and write use -rw
To verify this user account, we can query the agent from the agent machine only using the target as localhost.
snmpwalk -v3 -u snmpv3user -A snmpv3authPass -a SHA -X snmpv3encPass -x AES -l authPriv localhost
This command will attempt to walk the SNMP tree on the local machine using SNMPv3 with the specified credentials. If the SNMPv3 configuration is correct, you should see a list of SNMP OID (Object Identifier) values and their corresponding data.
To test with a particular OID. Append the OID in the end.
snmpwalk -v3 -u snmpv3user -A snmpv3authPass -a SHA -X snmpv3encPass -x AES -l authPriv localhost .1.3.6.1.2.1.2.2.1.2
SNMP Manager Configuration
If you want to fetch data of an SNMP agent from another machine that is called Manager, you need to install SNMP Manager software. Install an SNMP tool or SNMP manager software if not already installed. One common tool is snmpwalk. Install it using:
sudo yum install net-snmp-utils
Use the following command to perform an SNMP walk to test SNMPv3 connectivity and configuration. Replace ‘authUser’ with the username you created, and ‘yourTargetSNMPAgent’ with the IP address or hostname of the SNMP-enabled device:
snmpwalk -v3 -u authUser -l authNoPriv -a SHA -A yourAuthPassword -x DES -X yourPrivPassword yourTargetSNMPAgent
To test with an OID. Append the OID in the end.
snmpwalk -v3 -u authUser -l authNoPriv -A yourAuthPassword -a SHA -X yourPrivPassword -x AES yourTargetSNMPAgent .1.3.6.1.2.1.2.2.1.2