Configure SNMPv3 on CentOS

When you intend to monitor your devices using SNMP it’s best to use SNMP version 3 as it offers authentication and encryption. Both SNMP versions 1 and 2c only use the community-string as the password and all traffic is clear text. Configuring SNMPv3 on CentOS is pretty easy. In this lesson, I’ll show you how to do it.

I’m using a server running CentOS Stream 9 with net-snmp 5.9.1. I ran CentOS in a Docker container with systemd as its init system. That’s why the kernel version in the SNMP output below is the kernel of the Docker host, not a CentOS kernel.

First, install the required SNMP utilities.

# dnf install net-snmp net-snmp-utils

Make sure that the SNMP daemon is not running, or you will be unable to add a new user:

# systemctl stop snmpd

When the daemon is running, the script that we use in the next step refuses to add the user:

# net-snmp-create-v3-user -ro -A AUTH-PASS2 -X ENCRYPT-PASS2 -a SHA-256 -x AES RUNNINGUSER
Apparently at least one snmpd daemon is already running.
You must stop them in order to use this command.

Now we will create a new SNMPv3 user called “SNMPV3USER”. I will use SHA-256 from the Secure Hash Algorithm 2 (SHA-2) family for authentication and AES encryption, “AUTH-PASS” will be the password for authentication, and “ENCRYPT-PASS” will be used for encryption:

# net-snmp-create-v3-user -ro -A AUTH-PASS -X ENCRYPT-PASS -a SHA-256 -x AES SNMPV3USER
adding the following line to /var/lib/net-snmp/snmpd.conf:
   createUser SNMPV3USER SHA-256 "AUTH-PASS" AES "ENCRYPT-PASS"
adding the following line to /etc/snmp/snmpd.conf:
   rouser SNMPV3USER

The script writes the user to /var/lib/net-snmp/snmpd.conf and gives it read-only access in /etc/snmp/snmpd.conf.

The script also accepts MD5 and SHA (SHA-1) for authentication. For encryption, it only accepts AES, AES128, AES192, and AES256. When I tested this, -x DES didn’t give an error. The script used “DES” as the encryption password and kept AES:

# net-snmp-create-v3-user -ro -A AUTH-PASS -X ENCRYPT-PASS -a MD5 -x DES DESUSER
adding the following line to /var/lib/net-snmp/snmpd.conf:
   createUser DESUSER MD5 "AUTH-PASS" AES "DES"
adding the following line to /etc/snmp/snmpd.conf:
   rouser DESUSER

The snmpget and snmpwalk tools of this net-snmp build also refuse DES (Data Encryption Standard): “Invalid privacy protocol specified after -3x flag: DES”.

Now we can start the SNMP daemon:

# systemctl start snmpd

Make sure the SNMP daemon starts whenever you reboot your machine. You can do this with the systemctl enable command:

# systemctl enable snmpd
Created symlink /etc/systemd/system/multi-user.target.wants/snmpd.service → /usr/lib/systemd/system/snmpd.service.
# systemctl is-enabled snmpd
enabled
# systemctl is-active snmpd
active

The daemon is running now and systemd starts it when the machine boots. You are now ready to monitor your CentOS machine. Just to be sure, we can use snmpwalk to test if everything is reachable and working:

Sign up for FREE to Continue Reading

Here's what you'll get:

  • Full Access to this lesson + 447 more.
  • Learn CCNA, CCNP and CCIE R&S. Explained as simple as possible.
  • Unlock Access to 425 lessons by becoming a member.
  • New Lessons Added Regularly. You'll Be the First to Know.
  • Content created by Rene Molenaar (CCIE #41726)

Takes 1 minute - No credit card needed