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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. nmcli: command not found
  2. nordvpn Command Examples in Linux
  3. lvextend: command not found
  4. How to add a Custom Script to systemd in CentOS/RHEL 7
  5. How to move /usr and /var to Another Partition or Disk
  6. useradd: command not found
  7. modprobe: command not found
  8. envsubst: command not found
  9. Upgrading from CentOS/RHEL 7 to CentOS/RHEL 8 using Leapp
  10. Linux “rm” Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright