How to selectively use mutliple interfaces with Net-SNMP?
I have this monitoring network setting for Net-SNMP 5.7.2.1 listening to multiple Ethernet interfaces on my home gateway but it would only take the following combination from the snmpd.conf configuration file:
- single IP address
- single IP address, protocol-specific
- single IP address per unique protocol
such as:
agentAddress 127.0.0.1:161
or
agentAddress udp:127.0.0.1:161
or
agentAddress udp:127.0.0.1:161,udp6:[::1],tcp:127.0.0.1:161
But it would not accept multiple IP addresses using the same protocol, as given below as desired:
agentAddress udp:127.0.0.1:161,udp:172.28.130.1:161
How do I make SNMP daemon (snmpd) listen to TWO (or more) Ethernet interfaces
After digging through NetSNMP code a bit, it looks like it processes the config file line-by-line, and appends to the agent address data if it finds something.
Thus, you are able to add multiple lines in the config file with multiple agent addresses:
agentAddress udp:127.0.0.1:29032
agentAddress udp:127.0.0.1:22032
I was able to test this on my own agent built with NetSNMP...
$ snmpget -v3 -u myUser -l noAuthNoPriv 127.0.0.1:22032 1.3.6.1.4.1.1234.1.1.1
SNMPv2-SMI::enterprises.1234.1.1.1 = INTEGER: 2
$ snmpget -v3 -u myUser -l noAuthNoPriv 127.0.0.1:29032 1.3.6.1.4.1.1234.1.1.1
SNMPv2-SMI::enterprises.1234.1.1.1 = INTEGER: 2
Apparently, the only way to specify multiple interfaces for version Net-SNMP 5.7.2.1 is by specifying multiple IP addresses at the command line for snmpd.
I've yet to find a workable solution of specifying multiple interfaces using the snmpd configuration (snmpd.conf) file approach.
# /usr/sbin/snmpd 127.0.0.1 192.168.1.1
It is there (at the command line) that you can specify the protocol granularity (and continue to use the same protocol across multiple interfaces) like this:
# /usr/sbin/snmpd .... udp:127.0.0.1 udp:192.168.1.135:161 udp6:[::1]:161
I'd suggest that you can modify the systemd script rather than doing it manually on the command line.
For example, the current snmpd.service located in /usr/lib/systemd/system/ contains the following:
[Unit]
Description=Simple Network Management Protocol (SNMP) Daemon.
After=syslog.target network.target
[Service]
Type=notify
Environment=OPTIONS="-LS0-6d"
EnvironmentFile=-/etc/sysconfig/snmpd
ExecStart=/usr/sbin/snmpd $OPTIONS -f
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
Simply change that "ExecStart" line to contain what you'd like.
E.g.
ExecStart=/usr/sbin/snmpd $OPTIONS -f udp:127.0.0.1 udp:192.168.1.135:161 udp6:[::1]:161
NB: I've not tested this format, it may need to be around a different way with "-f" at the end or something - test and adjust. It stands to reason that it should work and then you have all the advantages of using systemd (which is being used anyway).
This platform snippet was from CentOS 7.3 so the location of snmpd.service may vary by distro. Find yours, make a copy of it to a .bak file and modify the original - test - enjoy.