{"id":7194,"date":"2020-10-29T22:32:48","date_gmt":"2020-10-29T19:32:48","guid":{"rendered":"https:\/\/kifarunix.com\/?p=7194"},"modified":"2024-03-14T23:19:06","modified_gmt":"2024-03-14T20:19:06","slug":"quick-way-to-install-and-configure-snmp-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/quick-way-to-install-and-configure-snmp-on-ubuntu-20-04\/","title":{"rendered":"Quick Way to Install and Configure SNMP on Ubuntu 20.04"},"content":{"rendered":"\n<p>In this guide, we are going to learn how to install and configure SNMP on Ubuntu 20.04. <a aria-label=\"SNMP (opens in a new tab)\" href=\"http:\/\/www.net-snmp.org\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">SNMP<\/a> is an acronym for Simple Network Management Protocol. It provides an agentless method of managing and monitoring of network devices and servers for health information, system metrics such as CPU load, Physical Memory usage, number of running processes, service state e.t.c that support polling over the&nbsp;<code>SNMP<\/code>&nbsp;protocol.. With this method, you don\u2019t need to install the usual Nagios NRPE agent on your hosts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing SNMP on Ubuntu 20.04<\/h2>\n\n\n\n<p>Before you can monitor Linux hosts via SNMP using monitoring tools like Nagios or Cacti, you first need to install and configure SNMP.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install SNMP<\/h3>\n\n\n\n<p>The SNMP packages are available on default Ubuntu 20.04 repositories.<\/p>\n\n\n\n<p>You first need to update your package cache;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<p>Once the update is done, install SNMP on Ubuntu 20.04.<\/p>\n\n\n\n<pre id=\"block-c6027bc5-5a26-43e5-831e-e4e24b4dcc2e\" class=\"wp-block-preformatted\">apt install snmpd snmp libsnmp-dev<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure SNMP on Ubuntu 20.04<\/h3>\n\n\n\n<p>Once the installation is done, proceed to configure SNMP as follows.<\/p>\n\n\n\n<p>The default configuration file for SNMP is&nbsp;<code>\/etc\/snmp\/snmpd.conf<\/code>. The file is highly commented and thus, we will only make a few changes. As a result, make a copy of the original file before you can proceed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/etc\/snmp\/snmpd.conf{,.bak}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring SNMP Authentication on Ubuntu 20.04<\/h3>\n\n\n\n<p>SNMP supports three versions of SNMP protocol;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SNMP <code>v1<\/code><\/li>\n\n\n\n<li>SNMP <code>v2c<\/code><\/li>\n\n\n\n<li>SNMP v<code>3<\/code><\/li>\n<\/ul>\n\n\n\n<p>Both SNMP version 1 and 2c provides authentication using&nbsp;<code><em>community string<\/em><\/code>, which is a shared secret between the agent and the client that is passed in clear text over the network<\/p>\n\n\n\n<p>SNMP version 3 supports user authentication and message encryption using a variety of protocols and is thus a bit more secure.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"brid-System_Monitoring_Tools-Net-SNMP-Configuring_Authentication-2c_community\">Configuring SNMP Version 2c Community on Ubuntu 20.04<\/h4>\n\n\n\n<p>As stated above, SNMP v2 provides access using a <code><strong>permission directive<\/strong><\/code>, a <strong><code>community string<\/code><\/strong> and the <strong><code>source Address<\/code><\/strong>. The source address can be IP of the monitoring server such as Nagios Server (SNMP server) or Cacti for example. This directive should be set in the format;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><em>directive<\/em> <em>community<\/em> [<em>source<\/em> [<em>OID<\/em>]]<\/code><\/pre>\n\n\n\n<p>Where<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>directive <\/strong><\/code>can be&nbsp;<code>rocommunity<\/code>&nbsp;(provides read-only access) or&nbsp;<code>rwcommunity<\/code>&nbsp;(provides read-write access)<\/li>\n\n\n\n<li><code><strong>source<\/strong><\/code> can be IP of the monitoring server such as Nagios Server (SNMP server) or Cacti for example<\/li>\n\n\n\n<li><code><strong>OID<\/strong><\/code> is the optional SNMP tree to provide access to. To configure SNMP v2c<\/li>\n<\/ul>\n\n\n\n<p>Therefore, edit the&nbsp;<code>snmpd<\/code>&nbsp;configuration file and configure it to listen on both a localhost and an interface IP. By default, SNMP agent on is set to allow connections originating from the localhost only.&nbsp;<\/p>\n\n\n\n<pre id=\"block-cdaa9717-0fae-4657-aa4b-7894aaab1132\" class=\"wp-block-preformatted\">vim \/etc\/snmp\/snmpd.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n###########################################################################\n# SECTION: Agent Operating Mode\n#\n#   This section defines how the agent will operate when it\n#   is running.\n...\n#agentaddress  127.0.0.1,[::1]\nagentAddress udp:127.0.0.1:161,udp:192.168.58.18:161\n<\/code><\/pre>\n\n\n\n<p>Also, configure it to allow the monitoring server (Cacti server in my case, with IP, 192.168.58.3) only to connect using the community string (<code>Ex@mPL3<\/code>).<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n#\nSECTION: Access Control Setup\n#\nThis section defines who is allowed to talk to your running\nsnmp agent.\n...\n<strong>rocommunity Ex@mPL3 192.168.58.3<\/strong>\n<\/code><\/pre>\n\n\n\n<p>Save and exit the configuration file.<\/p>\n\n\n\n<p>Note that for any changes to the configuration file to take effect, force the&nbsp;<code>snmpd<\/code>&nbsp;service to re-read the configuration by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart snmpd<\/code><\/pre>\n\n\n\n<p>If you can check, SNMP is now listening on two interfaces;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>netstat -nlpu|grep snmp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>udp        0      0 192.168.58.18:161       0.0.0.0:*                           36473\/snmpd         \nudp        0      0 127.0.0.1:161           0.0.0.0:*                           36473\/snmpd<\/code><\/pre>\n\n\n\n<p>If firewall is running, allow connection from the monitoring server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow from 192.168.58.3 to any port 161 proto udp<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify SNMP v2c Connection with Community String<\/h4>\n\n\n\n<p>Next, run the command below from the monitoring server to verify access to the host;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>snmpwalk -v2c -c Ex@mPL3 192.168.58.18<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\niso.3.6.1.2.1.1.1.0 = STRING: \"Linux ubuntu20.kifarunix-demo.com 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64\"\niso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10\niso.3.6.1.2.1.1.3.0 = Timeticks: (2891) 0:00:28.91\niso.3.6.1.2.1.1.4.0 = STRING: \"Me &lt;me@example.org&gt;\"\niso.3.6.1.2.1.1.5.0 = STRING: \"ubuntu20.kifarunix-demo.com\"\niso.3.6.1.2.1.1.6.0 = STRING: \"Sitting on the Dock of the Bay\"\niso.3.6.1.2.1.1.7.0 = INTEGER: 72\niso.3.6.1.2.1.1.8.0 = Timeticks: (2) 0:00:00.02\niso.3.6.1.2.1.1.9.1.2.1 = OID: iso.3.6.1.6.3.10.3.1.1\niso.3.6.1.2.1.1.9.1.2.2 = OID: iso.3.6.1.6.3.11.3.1.1\niso.3.6.1.2.1.1.9.1.2.3 = OID: iso.3.6.1.6.3.15.2.1.1\niso.3.6.1.2.1.1.9.1.2.4 = OID: iso.3.6.1.6.3.1\niso.3.6.1.2.1.1.9.1.2.5 = OID: iso.3.6.1.6.3.16.2.2.1\niso.3.6.1.2.1.1.9.1.2.6 = OID: iso.3.6.1.2.1.49\niso.3.6.1.2.1.1.9.1.2.7 = OID: iso.3.6.1.2.1.4\niso.3.6.1.2.1.1.9.1.2.8 = OID: iso.3.6.1.2.1.50\niso.3.6.1.2.1.1.9.1.2.9 = OID: iso.3.6.1.6.3.13.3.1.3\niso.3.6.1.2.1.1.9.1.2.10 = OID: iso.3.6.1.2.1.92\niso.3.6.1.2.1.1.9.1.3.1 = STRING: \"The SNMP Management Architecture MIB.\"\niso.3.6.1.2.1.1.9.1.3.2 = STRING: \"The MIB for Message Processing and Dispatching.\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"brid-System_Monitoring_Tools-Net-SNMP-Configuring_Authentication-3_user\">Configure SNMP Version 3 on Ubuntu 20.04<\/h3>\n\n\n\n<p>SNMP v3 uses a username, permission, security level, authentication and privacy passphrases to allow access. As a result, you need to create user for authenticating. When created, the user is added to the following configuration files;&nbsp;<code>\/etc\/snmp\/snmpd.conf<\/code>&nbsp;and&nbsp;<code>\/var\/lib\/net-snmp\/snmpd.conf<\/code>.<\/p>\n\n\n\n<p>Similarly, make a copy of the original configuration file just like we did above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/etc\/snmp\/snmpd.conf{,.bak}<\/code><\/pre>\n\n\n\n<p>Stop SNMP daemon<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl stop snmpd<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create SNMP v3 Authentication User<\/h4>\n\n\n\n<p>Create a read-only authentication user using the&nbsp;<code>net-snmp-create-v3-user<\/code>&nbsp;command. The command syntax is;<\/p>\n\n\n\n<p><code>net-snmp-create-v3-user [-ro] [-A authpass] [-a MD5|SHA] [-X privpass][-x DES|AES] [username]<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>net-snmp-create-v3-user -ro -A STrP@SSWRD -a SHA -X STr0ngP@SSWRD -x AES snmpadmin<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nadding the following line to \/var\/lib\/snmp\/snmpd.conf:\n   createUser snmpadmin SHA \"STrP@SSWRD\" AES \"STr0ngP@SSWRD\"\nadding the following line to \/usr\/share\/snmp\/snmpd.conf:\n   rouser snmpadmin\n<\/code><\/pre>\n\n\n\n<p>Start SNMP daemon and configure inbound Firewall rules to UDP port 161 as we did above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl start snmpd<\/code><\/pre>\n\n\n\n<p>Enable SNMP daemon to run on system reboot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable snmpd<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify SNMP v3 Connection <\/h4>\n\n\n\n<p>Test to verify that everything is working as expected.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>snmpwalk -v3 -a SHA -A STrP@SSWRD -x AES -X STr0ngP@SSWRD -l authPriv -u snmpadmin localhost | head<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\niso.3.6.1.2.1.1.1.0 = STRING: \"Linux ubuntu20.kifarunix-demo.com 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64\"\niso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10\niso.3.6.1.2.1.1.3.0 = Timeticks: (6269) 0:01:02.69\niso.3.6.1.2.1.1.4.0 = STRING: \"Me <a href=\"mailto:me@example.org\">me@example.org<\/a>\"\niso.3.6.1.2.1.1.5.0 = STRING: \"ubuntu20.kifarunix-demo.com\"\niso.3.6.1.2.1.1.6.0 = STRING: \"Sitting on the Dock of the Bay\"\niso.3.6.1.2.1.1.7.0 = INTEGER: 72\niso.3.6.1.2.1.1.8.0 = Timeticks: (1) 0:00:00.01\niso.3.6.1.2.1.1.9.1.2.1 = OID: iso.3.6.1.6.3.10.3.1.1\niso.3.6.1.2.1.1.9.1.2.2 = OID: iso.3.6.1.6.3.11.3.1.1\n<\/code><\/pre>\n\n\n\n<p>From a remote host;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>snmpwalk -v3 -a SHA -A STrP@SSWRD -x AES -X STr0ngP@SSWRD -l authPriv -u snmpadmin 192.168.58.18 | head<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\niso.3.6.1.2.1.1.1.0 = STRING: \"Linux ubuntu20.kifarunix-demo.com 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64\"\niso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10\niso.3.6.1.2.1.1.3.0 = Timeticks: (11693) 0:01:56.93\niso.3.6.1.2.1.1.4.0 = STRING: \"Me &lt;me@example.org&gt;\"\niso.3.6.1.2.1.1.5.0 = STRING: \"ubuntu20.kifarunix-demo.com\"\niso.3.6.1.2.1.1.6.0 = STRING: \"Sitting on the Dock of the Bay\"\niso.3.6.1.2.1.1.7.0 = INTEGER: 72\niso.3.6.1.2.1.1.8.0 = Timeticks: (1) 0:00:00.01\niso.3.6.1.2.1.1.9.1.2.1 = OID: iso.3.6.1.6.3.10.3.1.1\niso.3.6.1.2.1.1.9.1.2.2 = OID: iso.3.6.1.6.3.11.3.1.1\n<\/code><\/pre>\n\n\n\n<p>Great!! You have successfully setup SNMP v2c and SNMP v3 on an Ubuntu 20.04 system. You can now configure your server for polling from a remove monitoring server using SNMP strings or with SNMP v3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-snmp-on-centos-8\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Install and Configure SNMP on CentOS 8<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-snmp-on-debian-10-buster\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Install and Configure SNMP on Debian 10 Buster<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-configure-snmp-version-3-on-debian-9\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">How to Configure SNMP version 3 on Debian 9<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" class=\"rank-math-link\" href=\"https:\/\/kifarunix.com\/how-to-configure-snmp-version-2c-on-debian-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Configure SNMP Version 2c on Debian 9<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/nagios-snmp-monitoring-of-linux-hosts-on-alienvault-usm-ossim\/\" target=\"_blank\" class=\"rank-math-link\">Nagios SNMP Monitoring of Linux Hosts on AlienVault USM\/OSSIM<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to install and configure SNMP on Ubuntu 20.04. SNMP is an acronym for Simple Network Management<\/p>\n","protected":false},"author":3,"featured_media":7195,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,121,347],"tags":[349,2861,2863,276,2862,2864,1200],"class_list":["post-7194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-howtos","category-snmp","tag-community-string","tag-install-snmp-ubuntu-20-04","tag-setup-snmp-version-2c-on-ubuntu-20-04","tag-snmp","tag-snmp-ubuntu-20-04","tag-snmp-version-3-ubuntu-20-04","tag-ubuntu-20-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/7194"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=7194"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/7194\/revisions"}],"predecessor-version":[{"id":21523,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/7194\/revisions\/21523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/7195"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=7194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=7194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=7194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}