Ubuntu: install and configure the SNMP service

In this tutorial, I will explain to you how to install and configure the SNMP service on Ubuntu, which will then allow you to monitor the server using PRTG or Centreon for example.

We will first install the service on the Ubuntu server and then configure it so that it is accessible by the network with a “personalized” community.

Since the SNMP service is mainly installed on servers, we will perform the installation and configuration in SSH.

Install the SNMP service

The installation of the SNMP service is quite simple, it is done from the command line:

sudo apt install snmpd

Now that the service is installed, we will move on to its settings.

Configuring SNMP service on Ubuntu

The SNMP service is configured through the /etc/snmp/snmpd.conf file. In order to be able to monitor our Ubuntu server, we are going to modify two elements in the configuration.

  1. Make the snmp service listen to the network, by default it is only accessible on the loopback address (127.0.0.1)
  2. Add a community.

Open the SNMP service configuration file using nano with the following command:

sudo nano /etc/snmp/snmpd.conf

In the configuration file find the line below and comment out using # before

agentaddress 127.0.0.1,[::1]

Then add the following line below so that the snmp service listens to all the IPv4 addresses of the server:

agentaddress udp:161,udp6:[::1]:161

Now, we will add an SNMPV1 / SNMPv2C community in read-only (view).

The basic syntax is as follows:

rocommunity CommunityName default

In this way the community created will be accessible by everyone, to limit access to a network or an IP address, you must replace default by a CIRD notation.

rocommunity CommunityName 192.168.1.10/32

This way, the community will only be accessible to hardware with the IP address 192.168.1.10

It is especially important to apply an IP restriction if monitoring a web server at a provider.

Save and close the file (ctrl + x).

You must now restart the SNMP service to take the configuration into account.

sudo systemctl restart snmpd.service

All you have to do is add your server to your monitoring software.

It is possible to test the correct operation before using the tool SNMP Tester de PRTG.




Leave a Comment