• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to modify snmp service to listen to an alternative port in CentOS/RHEL

by admin

Follow steps below to check and change the default port (161) number on which snmp service would be listening.

NOTE: Similarly for each service there will be a port over which the service is binded to. There is a common miss conception that the port mapping is done over /etc/services file. This is just an alias mapping for the users to refer when connecting across the network. A protocol mapped again the port in the /etc/services file does not mean that the port is blocked or unblocked by a firewall or is definitely mapped again the service. It can be altered as the procedure shown below. It is a good practice to keep the file /etc/services intact as it’s a good reference point.

1. Make sure the service is started using the service command.

# service snmpd restart
Stopping snmpd:                                            [  OK  ]
Starting snmpd:                                            [  OK  ]
# service snmpd status 
snmpd (pid  14222) is running...

2. The below commands help to list the current ports over which the service would be listening

# netstat -npl | grep snmp
tcp       0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN          14222/snmpd         
udp       0      0 0.0.0.0:161                 0.0.0.0:*                                   14222/snmpd
# lsof -Pnl +M -i4 | grep -i snmp 
snmpd     14222        0    9u  IPv4 811629      0t0  TCP 127.0.0.1:199 (LISTEN)
snmpd     14222        0   11u  IPv4 811630      0t0  UDP *:161

Here,
-i4 is for ipv4
-i6 is for ipv6

3. Open the below file in any of the editor and uncomment the line starting with ‘OPTIONS‘ and add the agents to listen on. For more information can refer man page on snmpd.conf and snmpd.

# vi /etc/sysconfig/snmpd.options
# cat /etc/sysconfig/snmpd.options 
# snmpd command line options
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -x tcp:127.0.0.1:801 udp:127.0.0.1:802"

4. Restart the service for the changes to take effect.

# service snmpd restart
Stopping snmpd:                                            [  OK  ]
Starting snmpd:                                            [  OK  ]

5. The below output shows the new ports its litening on.

# netstat -npl | grep snmp
tcp        0      0 127.0.0.1:801               0.0.0.0:*                   LISTEN      14255/snmpd         
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      14255/snmpd         
udp        0      0 127.0.0.1:802               0.0.0.0:*                               14255/snmpd
# lsof -Pnl +M -i4 | grep -i snmp
snmpd     14255        0    9u  IPv4 811826      0t0  TCP 127.0.0.1:801 (LISTEN)
snmpd     14255        0   11u  IPv4 811827      0t0  TCP 127.0.0.1:199 (LISTEN)
snmpd     14255        0   12u  IPv4 811828      0t0  UDP 127.0.0.1:802 
NOTE: For CentOS/RHEL 6.x version the files are /etc/sysconfig/snmpd and /etc/sysconfig/snmptrapd.

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. Understanding /etc/security/limits.conf file
  2. CentOS / RHEL 5 : How to install and configure vsftpd server
  3. Beginners Guide to NFS in CentOS / RHEL
  4. flow: A static type checker for JavaScript
  5. Invalid ABI Option abi=aapcs-linux
  6. edgepaint: Colorize edges of a graph layout to clarify crossing edges
  7. Mutt, Mail and Telnet – Send mails from linux command line or terminal
  8. How to install/remove/query/update RPM packages in Linux (Cheat Sheet)
  9. csvclean: Finds and cleans common syntax errors in CSV files
  10. iostat: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright