Simple Network Management Protocol (SNMP) is an Internet-standard protocol that can be used to remotely retrieve operating statistics for routers and firewalls. Devices that usually support SNMP include routers, switches, servers, workstations, etc.
Monitoring tools such as MRTG, cacti use SNMP to retrieve information from routers to draw graphics. In this tutorial, we will introduce the installation and simple configuration of SNMP on Linux (CentOS 7, Ubuntu 16.04, Ubuntu 18.04).
SNMP is a protocol implemented on the application layer of the network stack. It is one of the widely accepted protocols for managing and monitoring network elements. The protocol was created to gather information from very different systems in a consistent manner.
Generally, a network profiled by SNMP will consist primarily of devices containing SNMP agents. An agent is a program that collects information about the hardware, organizes it into predefined entries, and responds to queries using the SNMP protocol. SNMP requires only a few basic components to work:
- Managed device: It is a computer configured to poll the SNMP agent for information. It can be any computer that can send query requests to the SNMP agent with the correct credentials. The main functions of SNMP Manager: query the agent, get the response from the agent, set variables in the agent and confirm asynchronous events from the agent
- Agent: These are software that runs on managed devices. They are responsible for collecting information about the local system and storing them in a queryable format. Update name Management Information Base (MIB).
- Network Management Station (NMS): It executes applications that monitor and control managed devices.
MIB A database that follows the standards that managers and agents follow. Each SNMP agent maintains a database of information describing the parameters of the managed devices. The SNMP manager uses this database to request specific information from the agent and further transform the information according to the needs of the network management system (NMS). The database commonly shared between agents and managers is our MIB.
Currently, there are 3 versions of SNMP.
- SNMP version 1: This provides device statistics and error reports without consuming a lot of system resources. Security is limited to community strings and access control based on the IP address of the query server. Data communication is not encrypted.
- SNMP version 2: This is called v2c, it expands the number of error codes supported, increases the size of counters used to track data, and has the ability to perform batch queries, which can load response packets into the data more efficiently.
- SNMP version 3: This version provides higher security and remote configuration capabilities than its predecessor. Access is not limited to single community strings for read-only and read / write access, as usernames and passwords are introduced. Support for encrypted SNMP data transmission and transmission error detection is also provided.
table of Contents
- 1) Install snmp on Linux
- 2) SNMP configuration
- 3) Test the SNMP service
- in conclusion
1) Install snmp on Linux
We will introduce snmp installation on ubuntu and centos
- Up ubuntu
# apt-get install -y snmpd snmp
- Up center
# yum install -y net-snmp net-snmp-utils
2) SNMP configuration
The configuration file for the SNMP service can be found at
/etc/snmp/snmpd.conf. Before modifying the file, copy the file with the following command
# cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
Following are the basic configuration parameters that can be used to configure SNMP.
- Group Community string For SNMP: Similar to user ID or password, allowing access to device statistics. The client computer will use this string to retrieve the data (to generate a monitoring chart). This is a required configuration parameter. Can be sure where you will see community . Defaults The value is public and therefore not secure because everyone knows it by default.
- Listening address: We can configure the SNMP agent to listen only on specific IP addresses as shown below
agentAddress udp:ip_address:161. The default port for SNMP listening is 161. The default behavior of the proxy is to listen on the standard UDP port on all interfaces.
- system message: It involves personal information, process / disk monitoring,
- syslocation: this is [typically physical] The location of the system.
- syscontact: This is the contact information for the administrator.
Our modified information should look like this, please note that there are other default values on the file that are not shown here
- Up Ubuntu
# Listen for connections on all interfaces (both IPv4 *and* IPv6) agentAddress udp:161,udp6:[::1]:161 # ACCESS CONTROL # view all included .22.214.171.124.2.1.1 view all included .126.96.36.199.188.8.131.52 #rocommunity public localhost # Default access to basic system info rocommunity my_password default -V all # rocommunity6 is for IPv6 rocommunity6 my_password default -V all sysLocation linoxide sysContact Me
# ACTIVE MONITORING # # send SNMPv1 traps trapsink localhost public # send SNMPv2c traps trap2sink localhost public
- Up Centos
# sec.name source community com2sec notConfigUser default my_comm # Make at least snmpwalk -v 1 localhost -c public system fast again. # name incl/excl subtree mask(optional) view systemview included .184.108.40.206.2.1 view systemview included .220.127.116.11.18.104.22.168 ## incl/excl subtree mask view all included .1 80 # variables through the snmpd.conf file: syslocation centos linoxide syscontact admin
For any configuration changes, the SNMP service needs to be restarted (
/etc/snmp/snmpd.conf)occur. This can be done in the following ways:
# service snmpd restart
Do with systemd
# systemctl restart snmpd.service
3) Test the SNMP service
You can use the snmpwalk command to test whether SNMP can read the system and interface MIB.
- Up Ubuntu
# snmpwalk -c my_password -v2c -O e 127.0.0.1 iso.22.214.171.124.126.96.36.199 = STRING: "Linux ubuntu-01 4.4.0-66-generic #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017 x86_64" iso.188.8.131.52.184.108.40.206 = OID: iso.220.127.116.11.1.8072.3.2.10 iso.18.104.22.168.22.214.171.124 = Timeticks: (1544) 0:00:15.44 iso.126.96.36.199.188.8.131.52 = STRING: "me
" iso.184.108.40.206.220.127.116.11 = STRING: "ubuntu-01" iso.18.104.22.168.22.214.171.124 = STRING: "linoxide" iso.126.96.36.199.188.8.131.52 = INTEGER: 72 iso.184.108.40.206.220.127.116.11 = Timeticks: (1) 0:00:00.01 iso.18.104.22.168.22.214.171.124.2.1 = OID: iso.126.96.36.199.188.8.131.52.1 iso.184.108.40.206.220.127.116.11.2.2 = OID: iso.18.104.22.168.22.214.171.124.1 iso.126.96.36.199.188.8.131.52.3.1 = STRING: "The MIB for Message Processing and Dispatching." iso.184.108.40.206.220.127.116.11.3.3 = STRING: "The SNMP Management Architecture MIB." iso.18.104.22.168.22.214.171.124.0 = Timeticks: (9971483) 1 day, 3:41:54.83 iso.126.96.36.199.188.8.131.52.0 = Hex-STRING: 07 E1 04 08 01 30 16 00 2B 00 00 iso.184.108.40.206.220.127.116.11.0 = INTEGER: 393216 iso.18.104.22.168.22.214.171.124.0 = STRING: "BOOT_IMAGE=/boot/vmlinuz-4.4.0-66-generic root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyS0 " iso.126.96.36.199.188.8.131.52.0 = Gauge32: 1 iso.184.108.40.206.220.127.116.11.0 = Gauge32: 121 iso.18.104.22.168.22.214.171.124.0 = INTEGER: 0
- Up Centos
# snmpwalk -c my_comm -v1 -O e 127.0.0.1 SNMPv2-MIB::sysDescr.0 = STRING: Linux centos-01 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (304) 0:00:03.04 SNMPv2-MIB::sysContact.0 = STRING: admin
(configure /etc/snmp/snmp.local.conf) SNMPv2-MIB::sysName.0 = STRING: centos-01 SNMPv2-MIB::sysLocation.0 = STRING: centos linoxide SNMPv2-MIB::sysORLastChange.0 = Timeticks: (8) 0:00:00.08 SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB
After confirming that SNMP is working properly, you can configure SNMP statistics collection software (such as MRTG) to create online graphs of traffic.
In this tutorial, we learn how to install and configure snmp on Linux to monitor network devices. Hope you enjoy reading and leave your suggestions in the comments section below.
- How to install and set up Cacti on Ubuntu 16.04
- How to install and configure MRTG on Ubuntu 18.04