How To Change the SNMP Port on CentOS

SNMP 101: The Basics
I. How To Install and Configure SNMP on CentOS
II. How To Change the SNMP Port on CentOS
Introduction

SNMP, or Simple Network Management Protocol, is widely used to communicate with and monitor network devices, servers, and more, all via IP. In the previous article we installed an SNMP agent on a CentOS 6.5 server. This agent allows for collection of data from our server, and makes the information available to a remote SNMP manager. To add a little security, we’ll now change the port that SNMP listens on.

Pre-Flight Check
  • These instructions are intended for changing the SNMP port.
  • I’ll be working from a Liquid Web Core Managed CentOS 6.5 server, and I’ll be logged in as root.
  • SNMP is installed and configured per the tutorial on How To Install and Configure SNMP on CentOS.

Change the SNMP Port

First, echo a new configuration into the SNMP configuration file:

echo OPTIONS=\"-LS0-5d -Lf /dev/null -p /var/run/snmpd.pid -x TCP:13371 UDP:13371\" >> /etc/sysconfig/snmpd

-LS0-5d specifies the logging level. In this case levels 0 through 5 will be logged; log levels are defined as follows:

0 or ! for LOG_EMERG,
1 or a for LOG_ALERT,
2 or c for LOG_CRIT,
3 or e for LOG_ERR,
4 or w for LOG_WARNING,
5 or n for LOG_NOTICE,
6 or i for LOG_INFO, and
7 or d for LOG_DEBUG.

-p /var/run/snmpd.pid saves the process ID of the daemon into /var/run/snmpd.pid.

-x TCP:13371 UDP:13371 listens on port 13371 (TCP and UDP) on all IPv4 interfaces. Port 13371 was used specifically for this tutorial, and can be replaced with a custom report number.

Now, restart the SNMP service to reload the new configuration file:

service snmpd restart

Test the SNMP Configuration

To verify that SNMP is now listening on the correct port use the following command:

netstat -lnp | grep snmp

Let’s test the SNMP configuration… try running the following two commands:

snmpwalk -v 2c -c idv90we3rnov90wer -O e 127.0.0.1:13371

Note: idv90we3rnov90wer is the “community” used in the previous tutorial; your community string will likely be different. If you’re going to connect to SNMP from a remote server, be sure your server’s firewall has the appropriate ports open
Be Sociable, Share!
Here's $75, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support.