使用 IPTables 限制每个源 IP 的 ICMP

Kyl*_*ndt 9 networking linux router iptables

我错误地认为限制模块是每个源ip的,但它似乎是基于所有请求的:

  577 36987 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 limit: avg 3/sec burst 5 
   46  3478 LOG        icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 LOG flags 0 level 4 prefix `INET-PING-DROP:' 
   46  3478 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 
    ...
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 limit: avg 3/sec burst 5 
    0     0 LOG        icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 LOG flags 0 level 4 prefix `WEB-PING-DROP:' 
    0     0 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8 
Run Code Online (Sandbox Code Playgroud)

如何根据源 IP 地址使用 iptables / netfilter 对 icmp 进行速率限制?

小智 5

如果您仍然想知道提示:

iptables -I INPUT -p icmp -m hashlimit --hashlimit-name icmp --hashlimit-mode srcip --hashlimit 3/second --hashlimit-burst 5 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

假设 INPUT 中的最后一条规则是 drop 或默认策略是 DROP。每个 ip 限制为每秒 3 次 ping(突发 5 次)。正如您使用 -m 限制发现的那样,并非所有传入的 IP 都是总数。