How to install snmp on RHEL 8 / CentOS 8

SNMP (Simple Network Management Protocol) is widely used for monitoring and central management purposes. In this tutorial we will install the snmpd service to a RHEL 8 / CentOS 8 machine, enable autostart, and after starting the service, we will test the functioning service with snmpwalk running the default settings.

In this tutorial you will learn:

  • How to install snmp service
  • How to start and enable the service with systemd
  • How to open udp port 161 for remote access
  • How to test the service with snmpwalk from localhost and remove machine

Snmpd answer to remote query with snmpwalk.

Snmpd answer to remote query with snmpwalk.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software snmpd 5.8
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install snmp on RHEL 8 / CentOS 8 step by step instructions

The net-snmp package is available in the base repositories after enabling Subscription Management repositories.

  1. First we need to install the package containing the snmpd service:
    # dnf install net-snmp
  2. To set the service to automatic start on boot, we use systemctl:
    # systemctl enable snmpd
  3. Let’s start the service:
    # systemctl start snmpd


  4. And verify it’s running state:
    # systemctl status snmpd -l
      snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
       Loaded: loaded (/usr/lib/systemd/system/snmpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Wed 2019-01-02 19:29:35 CET; 25min ago
     Main PID: 3217 (snmpd)
        Tasks: 1 (limit: 12544)
       Memory: 8.4M
       CGroup: /system.slice/snmpd.service
                 3217 /usr/sbin/snmpd -LS0-6d -f
  5. To test it, we’ll need the snmpwalk utility:
    # dnf install net-snmp-utils
  6. To test it from the command line, we’ll query the default public community (“rhel8lab” in the answer is the hostname of the lab machine):
    $ snmpwalk -v 2c -c public -O e 127.0.0.1
    SNMPv2-MIB::sysDescr.0 = STRING: Linux rhel8lab 4.18.0-32.el8.x86_64 #1 SMP Sat Oct 27 19:26:37 UTC 2018 x86_64
    SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
    DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (174237) 0:29:02.37
    SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
    SNMPv2-MIB::sysName.0 = STRING: rhel8lab
    [...]
  7. For remote access, we need to add a new service to firewalld. We create the text file /etc/firewalld/services/snmpd.xml with the following content:
    <?xml version="1.0" encoding="utf-8"?>
    <service>
      <short>SNMPD</short>
      <description>SNMP daemon</description>
      <port protocol="udp" port="161"/>
    </service>

    Open the firewall for the service:

    # firewall-cmd --zone=public --add-service snmpd --permanent

    And reload the firewall’s configuration:

    # firewall-cmd --reload
  8. Now we can query the machine remotely the same way as we did on localhost:
    $ snmpwalk -v 2c -c public -O e <hostname-or-ip-address-of-the-machine>