Snmpd侦听特定的IP地址(绑定到选定的接口)

时间:2020-01-09 10:42:06  来源:igfitidea点击:

如何强制SNMP(简单网络管理协议)网络管理软件在RHEL/RedHat/Fedora/CentOS Linux服务器下的公共接口上侦听?

net-snmp附带有snmpd服务器,它是SNMP代理,绑定到端口并等待SNMP管理软件的请求。
默认情况下,它仅绑定到本地主机(127.0.0.1)。

可以将snmpd配置为使用-x选项在所有IPv4接口或者选定接口上的UDP端口161上侦听传入的SNMP请求。
侦听地址的形式为:

[<transport-specifier>:]<transport-address>

几个例子

127.0.0.1:161           listen on UDP port 161, but only on the loopback interface.  This prevents snmpd being queried  remotely.   The
                               port specification ":161" is not strictly necessary since that is the default SNMP port.

       TCP:1161                listen on TCP port 1161 on all IPv4 interfaces.

       ipx:/40000              listen on IPX port 40000 on all IPX interfaces.

       unix:/tmp/local-agent   listen on the Unix domain socket /tmp/local-agent.

       /tmp/local-agent        is  identical  to  the  previous  specification, since the Unix domain is assumed if the first character of the
                                is '/'.

       PVC:161                 listen on the AAL5 permanent virtual circuit with VPI=0 and VCI=161 (decimal) on the first ATM adapter  in  the
                               machine.

       udp6:10161              listen on port 10161 on all IPv6 interfaces.

CentOS/RHEL/Fedora Linux特定配置

编辑/etc/sysconfig/snmpd.options,执行:

# vi /etc/sysconfig/snmpd.options

取消注释选项行。
如下添加-x选项以侦听默认端口161和IP 127.0.0.1和192.168.1.254

OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -x 127.0.0.1 192.168.1.254"

保存并关闭文件。
重新加载更改:

# service snmpd reload

更新/etc/sysconfig/iptables防火墙配置,以允许udp端口161上的通信:

# vi /etc/sysconfig/iptables

仅仅接受从192.168.1.0/24到UDP端口161的连接,执行:

-A RH-Firewall-1-INPUT -p udp s 192.168.1.0/24 -m udp --dport 161 -j ACCEPT

最后,重新启动iptables服务:

# service iptables restart

您可能还需要更新/etc/snmp/snmpd.conf以设置正确的公共社区和其他ACL设置。
有关更多详细信息,请参考snmpd.conf手册页。