iptables 规则可以操作 IP 集吗?

0xC*_*22L 5 linux firewall iptables ipset

iptables-extensions(8)set模块中描述并讨论了可以对 IP 的存在或不存在做出反应,或者更一般地说是对 IP 集的匹配。

但是,似乎没有一种方法可以使用iptables规则即时将项目附加到 IP 集。

这个想法是,如果我使用该recent模块,我可以暂时将某些不断尝试的 IP 列入黑名单并将它们添加到 IP 集中(这可能更快)。这意味着在这种情况下需要遍历的规则更少,并且据说与 IP 集匹配也更快。

0xC*_*22L 5

事实证明这可能的,使用 中SET描述的目标iptables-extensions(8)

SET
   This module adds and/or deletes entries from IP sets which can be defined by ipset(8).

   --add-set setname flag[,flag...]
          add the address(es)/port(s) of the packet to the set

   --del-set setname flag[,flag...]
          delete the address(es)/port(s) of the packet from the set

          where flag(s) are src and/or dst specifications and there can be no more
          than six of them.

   --timeout value
          when adding an entry, the timeout value to use instead of the default one
          from the set definition

   --exist
          when  adding  an  entry  if it already exists, reset the timeout value to
          the specified one or to the default from the set definition

   Use of -j SET requires that ipset kernel support is provided, which, for standard
   kernels, is the case since Linux 2.6.39.
Run Code Online (Sandbox Code Playgroud)

我没有找到它,因为我在找到set模块描述后没有进一步搜索。