{"id":29087,"date":"2022-03-24T03:48:36","date_gmt":"2022-03-24T03:48:36","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=29087"},"modified":"2022-12-23T06:20:20","modified_gmt":"2022-12-23T06:20:20","slug":"how-to-install-and-configure-snmp-agent","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-install-and-configure-snmp-agent\/","title":{"rendered":"How to install and configure snmp agent"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How to install and configure snmp agent service in Ubuntu?<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"715\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-97-1024x715.png\" alt=\"\" class=\"wp-image-29091\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-97-1024x715.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-97-300x210.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-97-768x537.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/image-97.png 1198w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">SNMP Manager Server<\/h4>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ sudo apt update\r\n$ sudo apt install snmp snmp-mibs-downloader<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">SNMP Agent Server<\/h4>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ sudo apt update\r\n$ sudo apt install snmpd<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring the SNMP Manager Server<\/h4>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">$ vi \/etc\/snmp\/snmp.conf\r\n\r\nIn this file, there are a few comments <span class=\"hljs-keyword\">and<\/span> a single un-commented line. To allow the manager to import the MIB files, comment out the mibs : line:\r\n\r\n\/etc\/snmp\/snmp.conf\r\n<span class=\"hljs-comment\"># As the snmp packages come without MIB files due to license reasons, loading<\/span>\r\n<span class=\"hljs-comment\"># of MIBs is disabled by default. If you added the MIBs you can reenable<\/span>\r\n<span class=\"hljs-comment\"># loading them by commenting out the following line.<\/span>\r\n<span class=\"hljs-comment\">#mibs :<\/span>\r\n\r\nSave <span class=\"hljs-keyword\">and<\/span> close snmp.conf by pressing CTRL+X, followed by Y, <span class=\"hljs-keyword\">and<\/span> then ENTER <span class=\"hljs-keyword\">if<\/span> you\u2019re using nano. You are now finished configuring the manager server, but you will still need to <span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">this<\/span> <span class=\"hljs-title\">server<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">help<\/span> <span class=\"hljs-title\">configure<\/span> <span class=\"hljs-title\">your<\/span> <span class=\"hljs-title\">agent<\/span> <span class=\"hljs-title\">server<\/span>.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring the SNMP Agent Server<\/h4>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">$ \/etc\/snmp\/snmpd.conf\r\n\r\nInside, you will have to make a few changes. These will mainly be used to bootstrap your configuration so that you can manage it from your other server.\r\n\r\nFirst, you need to change the agentAddress directive. Currently, it is set to only allow connections originating from the local computer. You\u2019ll need to comment out the current line, <span class=\"hljs-keyword\">and<\/span> uncomment the line underneath, which allows all connections.\r\n\r\n<span class=\"hljs-comment\">#  Listen for connections from the local system only<\/span>\r\n<span class=\"hljs-comment\">#agentAddress  udp:127.0.0.1:161<\/span>\r\n<span class=\"hljs-comment\">#  Listen for connections on all interfaces (both IPv4 *and* IPv6)<\/span>\r\nagentAddress udp:<span class=\"hljs-number\">161<\/span>,udp6:&#91;::<span class=\"hljs-number\">1<\/span>]:<span class=\"hljs-number\">161<\/span>\r\n\r\nThe user you are creating will be called bootstrap <span class=\"hljs-keyword\">and<\/span> will be used <span class=\"hljs-keyword\">as<\/span> a template in which to create your first actual user. The SNMP packages <span class=\"hljs-keyword\">do<\/span> this through a process of cloning the user\u2019s properties.\r\n\r\ncreateUser bootstrap MD5 temp_password DES\r\n\r\nNow that you have a <span class=\"hljs-keyword\">new<\/span> user specified, you can set up the level of access that this user will have. In this tutorial you will set this up <span class=\"hljs-keyword\">for<\/span> your bootstrap user, <span class=\"hljs-keyword\">and<\/span> also <span class=\"hljs-keyword\">for<\/span> the <span class=\"hljs-keyword\">new<\/span> user you will be creating, called demo.\r\n\r\nrwuser bootstrap priv\r\nrwuser demo priv\r\n\r\nWhen you are finished making these changes, save <span class=\"hljs-keyword\">and<\/span> close the file.\r\n\r\nTo implement these changes, restart the snmpd service on your agent server:\r\n\r\nsudo systemctl restart snmpd\r\n\r\nThe SNMP daemon will listen <span class=\"hljs-keyword\">for<\/span> connections on port :<span class=\"hljs-number\">161.<\/span> Configure UFW to allow connections from the manager server to this port:\r\n\r\nsudo ufw allow from manager_server_ip_address to any port <span class=\"hljs-number\">161<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Verifying Authentication to the Agent Server<\/h4>\n\n\n\n<p>In this step, you will test to make sure you can connect with your&nbsp;<strong>bootstrap<\/strong>&nbsp;account to the&nbsp;<strong>agent server<\/strong>. Before that, however, this tutorial will talk a bit about the general structure of sending an SNMP command.<\/p>\n\n\n\n<p>When using the suite of tools included in the&nbsp;<code>snmp<\/code>&nbsp;package (the&nbsp;<code>net-snmp<\/code>&nbsp;software suite), there are a few patterns in the way you must call the commands. The first thing to do is authenticate with the SNMP daemon that you wish to communicate with. This usually involves supplying a few pieces of information. The common ones are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>-v<\/code>: This flag is used to specify the version of the SNMP protocol that you would like to use. This tutorial will be using v3.<\/li><li><code>-c<\/code>: This flag is used if you are using SNMP v1 or v2-style community strings for authentication. Since you are using v3-style user-based authentication, you don\u2019t need to do this.<\/li><li><code>-u<\/code>: This parameter is used to specify the username that you wish to authenticate as. To read or modify anything using SNMP, you must authenticate with a known username.<\/li><li><code>-l<\/code>: This is used to specify the security level that you are connecting with. The possible values are\u00a0<code>noAuthNoPriv<\/code>\u00a0for no authentication and no encryption,\u00a0<code>authNoPriv<\/code>\u00a0for authentication but no encryption, and\u00a0<code>authPriv<\/code>\u00a0for authentication and encryption. The username that you are using must be configured to operate at the security level you specify, or else the authentication will not succeed.<\/li><li><code>-a<\/code>: This parameter is used to specify the\u00a0<em>authentication protocol<\/em>\u00a0that is used. The possible values are\u00a0<code>MD5<\/code>\u00a0or\u00a0<code>SHA<\/code>. This must match the information that was specified when the user was created.<\/li><li><code>-x<\/code>: This parameter is used to specify the\u00a0<em>encryption protocol<\/em>\u00a0that is used. The possible values are\u00a0<code>DES<\/code>\u00a0or\u00a0<code>AES<\/code>. This must match the information that was specified when the user was created. This is necessary whenever the user\u2019s privilege specification has\u00a0<code>priv<\/code>\u00a0after it, making encryption mandatory.<\/li><li><code>-A<\/code>: This is used to give the authentication passphrase that was specified when the user was created.<\/li><li><code>-X<\/code>: This is the encryption passphrase that was specified when the user was created. If none was specified but an encryption algorithm was given, the authentication passphrase will be used. This is required when the\u00a0<code>-x<\/code>\u00a0parameter is given or whenever a user\u2019s privilege specification has a\u00a0<code>priv<\/code>\u00a0after it, requiring encryption.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Using this information, you can construct your commands. Given how you set up your bootstrap user, the commands you will be using with that account will look like this:\r\n\r\n$ snmp_command -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password remote_host snmp_sub_command_or_options\r\n\r\nFrom your manager server, test to make sure your bootstrap account is available. Type the following to display the system information <span class=\"hljs-keyword\">for<\/span> the agent server:\r\n\r\n$ snmpget -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password agent_server_ip_address <span class=\"hljs-number\">1.3<\/span><span class=\"hljs-number\">.6<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.0<\/span>\r\n\r\nThe <span class=\"hljs-number\">1.3<\/span><span class=\"hljs-number\">.6<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.2<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.1<\/span><span class=\"hljs-number\">.0<\/span> string is the OID that is responsible <span class=\"hljs-keyword\">for<\/span> displaying system information. It will <span class=\"hljs-keyword\">return<\/span> the output of uname -a on the remote system.\r\n\r\nThis will give the following output:\r\n\r\nOutput\r\nSNMPv2-MIB::sysDescr<span class=\"hljs-number\">.0<\/span> = STRING: Linux agent <span class=\"hljs-number\">4.15<\/span><span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">-66<\/span>-generic <span class=\"hljs-comment\">#75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64<\/span>\r\nNow that you have verified that you can authenticate to the server running the SNMP daemon, you can <span class=\"hljs-keyword\">continue<\/span> on to create your regular user account.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">How to install and configure snmp agent service in Centos\/RHEL?<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">How to install and configure snmp agent service in Windows?<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>How to install and configure snmp agent service in Ubuntu? SNMP Manager Server SNMP Agent Server Configuring the SNMP Manager Server Configuring the SNMP Agent Server Verifying Authentication to the&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-29087","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=29087"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29087\/revisions"}],"predecessor-version":[{"id":29092,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/29087\/revisions\/29092"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=29087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=29087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=29087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}