4

I installed snmp on CentOS 7.2, like so:

yum -y install net-snmp net-snmp-utils

I made a backup of my snmpd.conf file:

cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig

then I cleared the text, with this:

echo "" > /etc/snmp/snmpd.conf

and added to the snmpd.conf, the following:

rocommunity "#random$" monitoring_server_ip

The monitoring_server_ip is the server that that is allowed to connect to this snmpd server.

Restarted snmpd

/bin/systemctl restart snmpd

When I run snmpwalk on my CentOS 7.2 server

snmpwalk -v2c -c public localhost system

I then get:

Timeout: No Response from localhost

Which is accurate, because there is only one IP-adres that can do that, as we have defined before.

ps shows that snmp is running

/usr/sbin/snmpd -LS0-6d -f

This is my first time playing with snmp and any help is greatly appreciated!

output of iptables -L -n | grep udp shows this:

...
Chain IN_public_allow (1 references)
   94  target     prot opt source               destination
   95  ACCEPT     udp  --  XX.XXX.XXX.XXX        0.0.0.0/0            udp dpt:161 ctstate NEW
...

All of the destination was too 0.0.0.0/0?

Netstat shows the following port:

 netstat -ulnp | grep 161
udp        0      0 0.0.0.0:161             0.0.0.0:*                           19062/snmpd

also this:

netstat -lu | grep snmp
udp        0      0 0.0.0.0:snmp            0.0.0.0:*

Also, in my firewall, added that only one IP-adres can access my snmp server:

firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="XX.XXX.XXX.XX" port protocol="udp" port="161" accept"
blade19899
  • 547
  • 5
  • 12
  • 25

1 Answers1

4

The com2sec security model is not mandatory anymore.

In snmpd.conf it should be enough to do:

rocommunity "#randomsometinh$"  2.2.2.2

where 2.2.2.2 is the monitoring IP address allowed to connect. I often prefer to assign a single IP, than giving access to a whole /24. So this configuration means the SNMP service will answer requests from the 2.2.2.2 address.

You might also have to comment the line that restricts the snmpd daemon to the localhost for security reasons.

# agentAddress  udp:127.0.0.1:161

After changing the configuration file, do:

service restart snmpd

To confirm if it is listening locally:

$ netstat -lu | grep snmp
udp        0      0 *:snmp                  *:* 

And from the allowed network/IP, for walking the entire MIB tree. Assuming 2.2.2.1 is the machine being monitored:

snmpwalk -c "#randomsometinh$" -v2c 2.2.2.1

or for asking for the sysUpTime OID:

snmpwalk -c "#randomsometinh$" -v2c 2.2.2.1 1.3.6.1.2.1.1.3
snmpget -c #randomsometinh$ -v2c 2.2.2.1 1.3.6.1.2.1.1.3.0

snmpget has to have the 0 for the specific object instance/index.

P.S: 2.2.2.2 is the monitoring server, and 2.2.2.1 is the snmpd server/host to be monitored.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227