Complete snmp installation, configuration, startup, and remote testing process on Ubuntu

Source: Internet
Author: User
Tags snmp http snmpwalk
0. it indicates that a complete tutorial is still the same sentence. Domestic courses are either incomplete or old, and their ideas are not clear, so here is a complete article to share with you. Although the monitoring of Linux Hosts can be completed by executing specific commands, it is easier to obtain the information of Linux Hosts through snmp than later, however, the configuration before use may take a little more time, but this is definitely worth it! In addition, if you need to develop monitoring software for Linux Hosts, using snmp is certainly the first choice. After all

0. Description

For a complete tutorial, the domestic course is either incomplete or too old, and the idea is not clear, so I will write a complete article here to share with you.

Although the monitoring of Linux Hosts can be completed by executing specific commands, it is easier to obtain the information of Linux Hosts through snmp than later, however, the configuration before use may take a little more time, but this is definitely worth it! If you need to develop monitoring software for Linux Hosts, using snmp is certainly the first choice. After all, it can obtain too much information!

The following describes how to install, configure, start snmp, and perform remote testing on Ubuntu.

The operating system used here is: Ubuntu 15.10

--------------------------------------------------------------------------------

1. Install

We need to install the following three software packages:

Snmpd: snmp server software

Snmp: snmp client software

Snmp-mibs-downloader: software used to download and update the local mib Library

Although I will use another host for remote testing, at the beginning, I installed the snmp client software on the server to facilitate some basic tests.

Run the following command to install the three software:

Ubuntu @ linuxidc :~ $ Sudo apt-get install snmpd snmp-mibs-downloader

Note that during the installation of snmp-mibs-downloader, the program will automatically download the mib library and save it in the/usr/share/mibs directory:

Ubuntu @ linuxidc:/usr/share/mibs $ ls

Iana ietf

If some directories or files are not found, you can manually execute the following command to download the mib library after installing snmp-mibs-downloader:

Ubuntu @ linuxidc :~ $ Sudo download-mibs

There will be a lot of output information.

In this case, the first step of installation is complete.

--------------------------------------------------------------------------------

2. Configuration

In fact, after installing the snmpd software, the system automatically enables this service for us:

12 ubuntu @ linuxidc :~ $ Sudo service snmpd status

* Snmpd is running

Before starting the configuration, let's perform some simple tests to see if the service is normal:

Ubuntu @ linuxidc :~ $ Snmpwalk-v 2c-c public localhost 1.3.6.1.2.1.1.1

Iso.3.6.1.2.1.1.1.0 = STRING: "Linux linuxidc 4.2.0-34-generic # 39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64"

No problem. If information is returned, you can perform various configurations directly. However, back up the configuration file before starting the Configuration:

Ubuntu @ linuxidc :~ $ Cd/etc/snmp

Ubuntu @ linuxidc:/etc/snmp $ sudo cp snmpd. conf snmpd. conf. ori

Ubuntu @ linuxidc:/etc/snmp $ ls snmpd *

Snmpd. conf snmpd. conf. ori

Of course, it should be noted that, as mentioned later, we use SNMPv2, which can meet our needs.

(1) Configure nodes

Modify the/etc/snmp/snmpd. conf file in about 45 lines and comment out the following two lines:

View systemonly supported ded. 1.3.6.1.2.1.1

View systemonly supported ded. 1.3.6.1.2.1.25.1

Add the following line:

View systemonly supported ded. 1

In this way, we can obtain more node information, because if we do not do this, we can obtain only the information contained in the above two commented nodes.

After the modification, restart the snmp service and use the following command to observe:

Ubuntu @ linuxidc:/etc/snmp $ sudo service snmpd restart

Xplinuxidc @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c public localhost. 1.3.6.1.4.1.2021.4.3.0

Iso.3.6.1.4.1.2021.4.3.0 = INTEGER: 1950716

OK, no problem! However, 1.3.6.1.4.1.2021.4.3.0 indicates a node of the total swap space of a LInux host. If the output is 1950716, the total swap space on our host is about 2 GB.

(2) configure the MIB Library

Although the above information can be obtained normally, the output result is not intuitive. Now we can configure the MIB library, but note that, this configuration is used to configure the client software (but still operate on the same server host ).

Modify the/etc/snmp. conf configuration file and comment out the following line:

Mibs:

Restart the snmp service and run the following command:

Ubuntu @ linuxidc:/etc/snmp $ sudo service snmpd restart

Ubuntu @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c public localhost. 1.3.6.1.4.1.2021.4.3.0

UCD-SNMP-MIB: memTotalSwap.0 = INTEGER: 1950716 kB

As you can see, the current output is very intuitive! In this case, when we get the relevant node information, we do not need to enter that long string of numbers:

Ubuntu @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c public localhost memTotalSwap.0

UCD-SNMP-MIB: memTotalSwap.0 = INTEGER: 1950716 kB

Ubuntu @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c public localhost memTotalReal.0

UCD-SNMP-MIB: memTotalReal.0 = INTEGER: 8093524 kB

In fact, you will be able to find out how powerful snmp is! You do not need to remember where the node values of the MIB library come from. You can find them online or read a blog article I have summarized: Common node values of linux snmp. you can also find http://xplinuxidc.blog.51cto.com on my blog. Of course, if you want to know what it means and why it should be defined like this, I suggest you go to the relevant professional books. A good recommendation is "TCP/IP details Volume 1: protocol, if the network is not good, you can also learn.

Note that configuration and testing are only performed on the server. In fact, this step should be completed on the client (on another host) for convenience.

(3) configuration community

In fact, the so-called Community can be understood as a password. When we used the snmpwalk command to obtain host information, there was a-c public parameter, in fact, this community is specified as public, which is the default configuration. Of course, in practice, we cannot use the default value, so we need to modify it.

Modify the configuration file/etc/snmp/snmpd. conf in 52 rows:

Rocommunity public default-V systemonly

Rocommunity6 public default-V systemonly

To:

Rocommunity xplinuxidc123 default-V systemonly

Rocommunity6 xplinuxidc123 default-V systemonly

Here we will change the community to xplinuxidc123, restart the snmp service, and observe through the command:

Ubuntu @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c public localhost memTotalReal.0

Timeout: No Response from localhost

Ubuntu @ linuxidc:/etc/snmp $ snmpwalk-v 2c-c xplinuxidc123 localhost memTotalReal.0

UCD-SNMP-MIB: memTotalReal.0 = INTEGER: 8093524 kB

We can see that the first retrieval of information failed because the Community has been updated and the old public will no longer be available. Otherwise, the authentication will fail and the host information provided by snmp will not be available.

(4) allow remote host access

By default, the snmp service is only enabled locally and cannot remotely obtain the snmp information of the Host:

Ubuntu @ linuxidc:/etc/snmp $ sudo netstat-antup | grep 161

Udp 0 0 127.0.0.1: 161 0.0.0.0: * 11615/snmpd

As you can see, port 161 is only open to the Local Machine (port 161 is the port number of the snmp service). We need to modify it to make the snmp service open to the outside world.

Modify the/etc/snmp/snmpd. conf configuration file in about 15 lines and comment out the following line:

AgentAddress udp: 127.0.0.1: 161

Remove the following comments:

# AgentAddress udp: 161, udp6: [: 1]: 161

Restart the snmp service and observe through the command:

Ubuntu @ linuxidc:/etc/snmp $ sudo netstat-antup | grep 161

Udp 0 0 0.0.0.0: 161 0.0.0.0: * 11656/snmpd

Udp6 0 0: 1: 161: * 11656/snmpd

We can see that the service is open to the outside world and supports both IPv4 and IPv6.

In this way, we can perform a test on the remote host.

--------------------------------------------------------------------------------

3. Start

In fact, we have always started the snmp service for the previous operations, but we still need to ensure that:

Ubuntu @ linuxidc :~ $ Sudo service snmpd start

Ubuntu @ linuxidc :~ $ Sudo netstat-antup | grep 161

Udp 0 0 0.0.0.0: 161 0.0.0.0: * 11656/snmpd

Udp6 0 0: 1: 161: * 11656/snmpd

--------------------------------------------------------------------------------

4. (remote) test

We have tested the server locally and there is no problem. What we need to do next is to test it on a remote host.

The operating system on my other remote host is also Ubuntu 15.04. I have installed the snmp client software and the mib library to download the software, and configured the MIB library. Then I will perform a remote test:

Xplinuxidc @ linuxidc :~ $ Snmpwalk-v 2c-c xplinuxidc123 115. 159. *. * memTotalSwap.0

UCD-SNMP-MIB: memTotalSwap.0 = INTEGER: 1950716 kB

Xplinuxidc @ linuxidc :~ $ Snmpwalk-v 2c-c xplinuxidc123 115. 159. *. * memTotalReal.0

UCD-SNMP-MIB: memTotalReal.0 = INTEGER: 8093524 kB

Xplinuxidc @ linuxidc :~ $ Snmpwalk-v 2c-c xplinuxidc123 115. 159. *. *. 1.3.6.1.4.1.2021.9.1.6.1

UCD-SNMP-MIB: dskTotal.1 = INTEGER: 8123832

As you can see, there is no problem with the test! The obtained value is the same as that obtained locally by the preceding server.

Of course, if you still cannot get it, you need to consider whether the firewall settings on the server host are correct.

--------------------------------------------------------------------------------

5. What is the purpose?

If you have a background development language (such as Python), and your front-end basics are good (such as html, js, jquery, bootstrap, and ajax), based on snmp, then you can develop a Linux host monitoring host by yourself. This is not difficult. The complicated thing is how you process your data, however, we need to look at the needs of everyone or every company.

Bloggers are currently developing related monitoring software, but they are not monitoring Linux Hosts, but other network devices. Although it is a little complicated, however, as long as the technical thinking is correct, everything will be fine.

It seems that snmp is very useful for most of my friends, so I will write this article to share it, although it is only for Ubuntu

However, in other Linux releases, I believe it is similar. In other words, I hope to help those who need it.

Ubuntu installation snmp reports Unlinked OID in IPATM-IPMC-MIB: marsMIB ::={ mib-2 57} error http://www.linuxidc.com/Linux/2015-08/122508.htm

Monitor Linux Server http://www.linuxidc.com/Linux/2015-07/119471.htm with SNMP and Cacti

Configure SNMPv3 http://www.linuxidc.com/Linux/2014-10/108511.htm on Ubuntu 14.04

SNMP http://www.linuxidc.com/Linux/2013-09/90263.htm for Zabbix

Network Dynamic Analysis http://www.linuxidc.com/Linux/2013-04/83514.htm Based on SNMP

SNMP Network Status Monitoring http://www.linuxidc.com/Linux/2013-04/83187.htm

Building SNMP test environment http://www.linuxidc.com/Linux/2013-02/79233.htm in CentOS 6.3

Linux (Ubuntu/CentOS) SNMP configuration http://www.linuxidc.com/Linux/2012-12/76837.htm

Enable and configure the SNMP service http://www.linuxidc.com/Linux/2013-01/78487.htm for Citrix Xenserver

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2016-03/129618.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.