简体   繁体   English

如何在Linux中更改net-snmp陷阱发送方端口?

[英]How to change the net-snmp trap sender port in linux?

I'm using the net-snmp for gather system information in linux. 我正在使用net-snmp来收集linux中的系统信息。 but I found there is problem. 但我发现有问题。

when I check port usage of Net-SNMP by netstat, I found net-snmp using 3 UDP port. 当我通过netstat检查Net-SNMP的端口使用情况时,我发现使用3个UDP端口的net-snmp。

Here is the result. 这是结果。

[root@ snmp]# netstat -anp | grep snmp

tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      6392/snmpd          
udp        0      0 0.0.0.0:49005               0.0.0.0:*                               6392/snmpd          
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               6392/snmpd          
udp        0      0 0.0.0.0:44837               0.0.0.0:*                               6392/snmpd    

as you can see, the snmpd using 2 more udp port without 161. also I found why the 2 udp ports are randomly occupied by snmp. 如您所见,snmpd使用了另外两个不带161的udp端口。我也发现了为什么2个udp端口被snmp随机占用。

those ports are using for sending snmp trap. 这些端口用于发送snmp陷阱。 when I remove the tran2sink and informsink option, the 2 UDP ports are no more appear. 当我删除tran2sink和notifysink选项时,不再显示2个UDP端口。

this is my part of configuration of snmpd.conf 这是我配置snmpd.conf的一部分

###########################################################################
# SECTION: Trap Destinations
#
#   Here we define who the agent will send traps to.

# trap2sink: A SNMPv2c trap receiver
#   arguments: host [community] [portnum]

trap2sink  192.168.1.4  

# informsink: A SNMPv2c inform (acknowledged trap) receiver
#   arguments: host [community] [portnum]

informsink  192.168.1.4 NMS_COM 

# trapcommunity: Default trap sink community to use
#   arguments: community-string

trapcommunity  NMS_COM

# authtrapenable: Should we send traps when authentication failures occur
#   arguments: 1 | 2   (1 = yes, 2 = no)

authtrapenable  1

my program have to use 40000~50000 udp port. 我的程序必须使用40000〜50000 udp端口。 so I want to use those trap options and change the ports. 所以我想使用这些陷阱选项并更改端口。

how can I fix the ports? 如何修复端口?

You can try to set port for the directives as below: 您可以尝试为指令设置端口,如下所示:
trap2sink 1.1.1.1:port_num eg trap2sink 1.1.1.1:162 trap2sink 1.1.1.1:port_num例如trap2sink 1.1.1.1:162


I hope I understood your question and this would help. 希望我理解您的问题,对您有所帮助。

These are SNMP Ephemeral ports. 这些是SNMP临时端口。 Here is a quote from a Microsoft support page on them: 这是来自Microsoft支持页面上的报价:

While SNMP service is running it may be noticed via the netstat Command Line utility that in addition to the well known ports for sending and receiving SNMP traps (161/162) that a random ephemeral port has been created by the service as well. 在SNMP服务运行时,可以通过netstat命令行实用程序注意到,除了众所周知的用于发送和接收SNMP陷阱的端口(161/162)外,该服务还创建了一个随机临时端口。

The random port usage is intended behavior and is opened for the purpose of sending "management" traps 随机端口的使用是预期的行为,并且为了发送“管理”陷阱而打开

... ...

This port will remain in the system while the SNMP service is running, but is not actively used unless a management trap is to be sent outbound. SNMP服务运行时,此端口将保留在系统中,但是除非将管理陷阱发送到外部,否则该端口不会被有效使用。 Since SNMP does not listen for inbound packets on this random port, this does not present a security vulnerability. 由于SNMP不会在此随机端口上侦听入站数据包,因此不会出现安全漏洞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM