How to set up snmpd to listen on an alternative port (other than 161)?

7,206

How to get snmpd listen on a port other than 161 on CentOS 6.x:

Install these snmp packages if not installed yet:

sudo yum install net-snmp net-snmp-utils

Choose a port number that is suitable for you and is not included in /etc/services.

Say I chose 58001.

Add the following line in /etc/snmp/snmpd.conf:

agentAddress udp:58001

Start the service:

service snmpd start

and/or enable automatic start of snmpd on system boot:

sudo chkconfig --add snmpd
sudo chkconfig snmpd on
Share:
7,206

Related videos on Youtube

Antonio Ceballos
Author by

Antonio Ceballos

Updated on September 18, 2022

Comments

  • Antonio Ceballos
    Antonio Ceballos over 1 year

    I am working on a CentOS 6.4 64-bit, as root. I am trying to set up the system snmpd agent, so that it listens on a port other than 161, e.g. 8001. I successfully got that on Debian 7.x by just changing the port number in /etc/snmp/snmpd.conf:

    agentAddress  udp:127.0.0.1:8001
    

    and restarting the service with /etc/init.d/snmpd restart. It was straightforward. However, I tried several things but I didn't manage to do that on CentOS, i.e. snmpd will fail to start.

    These are the last two lines written in /var/log/messages when I try to run it with that line in snmpd.conf:

    Oct 13 15:47:40 localhost snmpd[4775]: Error opening specified endpoint "udp:127.0.0.1:8001"
    Oct 13 15:47:40 localhost snmpd[4775]: Server Exiting with code 1
    

    On the other hand, if I run the program directly, it will start and will happily open port 8001:

    /usr/sbin/snmpd udp:127.0.0.1:8001
    

    or:

    /usr/sbin/snmpd udp:8001
    

    Both ways work.

    I have googled and read about /etc/sysconfig/snmpd, but adding some options in this file did not work either. For info, I disabled iptables (ipdatables -F).

    Could anybody help me on this?

    Thanks in advance, Antonio

    • Antonio Ceballos
      Antonio Ceballos over 8 years
      I fixed the problem by myself once I realized that UDP port 8001 was declared in /etc/services. As soon as I changed it by an undeclared port, it worked. Whether /etc/services is actually the root cause or not, I could not say for sure.
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 8 years
      Nice to hear you figured it out! You should either post your solution as an actual answer, or delete your question.