For the load, you can not worry too much if in one chain iptables is not much more than 1000 rules. The kernel processes each chain that is hit by the control, strictly sequentially. Because of this, going through a large number of rules will begin to slow down. If the rules are supposed to be significantly more than 1000, then think up an algorithm for splitting them into several chains, each of which is called only for a certain type of packet or a certain ip range. For example, break the rules by subnets:
iptables -N RULE_10 iptables -A RULE_10 -s 10.0.0.1 -j DROP iptables -A RULE_10 -s 10.0.10.41 -j DROP ... iptables -N RULE_192 iptables -A RULE_192 -s 192.168.0.1 -j DROP iptables -A RULE_192 -s 192.168.50.48 -j DROP ... iptables -A INPUT -s 10.0.0.0/8 -j RULE_10 iptables -A INPUT -s 192.0.0.0/8 -j RULE_192
According to a similar scheme (although more complicated because of the uneven distribution of the number of rules across subnets), I have easily processed 35,000 rules. A 3-level chaining system is used, on the upper and 2nd levels of which there are about 30 rules, at the 3rd level, on average, 50-200 rules.
But such a complex scheme had to be used only by the fact that on that machine there was a rather old kernel that I don’t want to change and there is no possibility to use a much better solution :
Iptables ipset module . This module consists of two parts, the actual module for iptables and the separate ipset management utility . The bottom line is that if we have the same type of rules that filter by ip-address or, for example, by port numbers, we create lists using this same utility. And in iptables itself, there is literally one rule added:
ipset create mailBlock hash:ip >/dev/null 2>&1 iptables -I INPUT -m set --match-set mailBlock src -p tcp --dport 25 -j DROP
Many ip-addresses can be entered into the list itself; their processing at the kernel level works not through enumeration, but through hash tables, which is very fast.