• 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. IBM DB2 Installation on Red Hat Enterprise Linux
  2. How to use fdisk to partition a disk in Linux
  3. How To Limit/Restrict FTP Commands On Vsftpd Services (CentOS/RHEL 6,7)
  4. CentOS / RHEL LVM : Backing Up Volume Group Metadata
  5. CentOS / RHEL 6,7 : How to configure hugepages
  6. How to recover from a corrupt RPM database (rebuilding an RPM database)
  7. Manual Changes Made To /etc/hosts Or /etc/sysconfig/network-scripts/ifcfg-* Are Lost
  8. 7 Useful Find Command Examples to Locate files to remove when a filesystem is full
  9. RHEL / CentOS : How to shrink LVM volume
  10. “yum update” fails with “[package version 1] is a duplicate with [package version 2]”

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright