Setting up SNMP Master Agent on Ubuntu 17.04 and Centos 7.4
Overview
If you’re unfamiliar with setting up SNMP, I recommend reading our guide on the basic principles of SNMP[1]. SNMP, or Simple Network Management Protocol, is a widely-used protocol for monitoring and configuring various network devices. To set up a functional SNMP configuration, we’ll need to establish an agent to collect information from a target machine and a master to initiate requests. In this tutorial, we’ll quickly configure a network with two Linux machines—one serving as the agent and the other as the master.
Prerequisites:
- Centos 7.4 VPS server (or a local machine)
- Ubuntu 17.04 VPS server (or a local machine)
- Basic knowledge of installing packages, modifying configuration files, and running commands
- Familiarity with the basic principles of SNMP[2]
Configuration
CentOS System: The CentOS system will function as the agent. Requests will be sent to this system to gather information about it.
1) Identify the IP address of the machine and take note of it, or record it for reference.
ip addr show
2) Install the SNMP agent package on the CentOS system.
yum -y install net-snmp
3) Verify the default configuration settings.
grep -v '^$\|^\s*\#' /etc/snmp/snmpd.conf
4) Create a backup of the original configuration.
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
5) Create an empty `/etc/snmp/snmpd.conf` file and populate it with the following content:
rocommunity vpsservers 185.181.8.0/24
# setup info
syslocation "my Centos VPS server"
syscontact "My Contact name"
# open up
agentAddress udp:161
# run as
agentuser root
# dont log connection from UDP:
dontLogTCPWrappersConnects yes
# fix for larger then 2TB disks (raid!)
realStorageUnits 0
IMPORTANT: Ensure to set the SNMP community string and define the network from which connections will be accepted. Update the configuration accordingly.
6) Now, let’s reduce the verbosity of the SNMP service. Edit the /etc/sysconfig/snmpd
file, uncomment the OPTIONS string, and configure it as follows:
OPTIONS="-Ls3d"
7) Now, start and enable the SNMP service, and ensure that it is running without any issues.
systemctl start snmpd
systemctl enable snmpd
systemctl status snmpd
Ubuntu: For this setup, I am using another VPS server dedicated to Ubuntu.
1) Install the SNMP and SNMP MIBs downloader packages by executing the following commands:
apt-get install snmp
apt-get install snmp-mibs-downloader
2) Now, let’s attempt to query information from our agent:
snmpwalk -Os -c vpsservers -v1 185.181.8.68 SNMPv2-MIB::sysDescr.0
snmpwalk -Os -c vpsservers -v1 185.181.8.68 SNMPv2-MIB::sysUpTime.0
In Summary
Now you have successfully set up a real-life SNMP master-agent configuration, allowing you to make requests to your SNMP agent and retrieve information. This marks the initial step toward establishing a fully monitored system. You can explore attributes to query in /var/lib/snmp/mibs/ietf/SNMPv2-MIB
. For instance:
sysDescr
sysObjectID
sysUpTime
sysContact
sysName
sysLocation
sysServices
sysORLastChange
sysORTable
sysOREntry
sysORIndex
sysORID
sysORDescr
sysORUpTime
snmpInPkts
snmpInBadVersions
snmpInBadCommunityNames
snmpInBadCommunityUses
snmpInASNParseErrs
snmpEnableAuthenTraps
snmpSilentDrops
snmpProxyDrops
snmpTrapOID
snmpTrapEnterprise
snmpSetSerialNo
snmpOutPkts
snmpInTooBigs
snmpInNoSuchNames
snmpInBadValues
snmpInReadOnlys
snmpInGenErrs
snmpInTotalReqVars
snmpInTotalSetVars
snmpInGetRequests
snmpInGetNexts
snmpInSetRequests
snmpInGetResponses
snmpInTraps
snmpOutTooBigs
snmpOutNoSuchNames
snmpOutBadValues
snmpOutGenErrs
snmpOutGetRequests
snmpOutGetNexts
snmpOutSetRequests
snmpOutGetResponses
snmpOutTraps
[1]: https://www.blendhosting.com/kb/essential-principles-of-snmp-tutorial/
[2]: https://www.blendhosting.com/kb/essential-principles-of-snmp-tutorial/