IPTables rules for SNMP

In this article, I will give an example of IPTables rules for SNMP.
Let’s say “iptables -P INPUT DROP” is the default, which is very desirable.

To allow accepting SNMP connections, for example, for the network 192.168.0.0/24:

sudo iptables -A INPUT -p udp -m udp -s 192.168.0.0/24 --dport 161 -j ACCEPT

To accept SNMP Traps:

sudo iptables -A INPUT -p udp -m udp -s 192.168.0.0/24 --dport 162 -j ACCEPT

To remove a rule, specify the same command, replacing -A with -D, for example:

sudo iptables -D INPUT -p udp -m udp -s 192.168.0.0/24 --dport 162 -j ACCEPT

See also my article:
How to configure IPTables

Leave a comment

Leave a Reply