大网数据广告活动
服务器运维问答

How to reset iptables rate limit counter?

· 52CE 我爱测

I implemented SSH connection rate limiting using the following. iptables -N SSH_BRUTE_FORCE_MITIGATION iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --set iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH …

问题原文

原帖链接 · sunknudsen · CC BY-SA 4.0

I implemented SSH connection rate limiting using the following.

iptables -N SSH_BRUTE_FORCE_MITIGATION
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --set
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --update --seconds 300 --hitcount 10 -m limit --limit 1/second --limit-burst 100 -j LOG --log-prefix "iptables[ssh-brute-force]: "
iptables -A SSH_BRUTE_FORCE_MITIGATION -m recent --name SSH --update --seconds 300 --hitcount 10 -j DROP
iptables -A SSH_BRUTE_FORCE_MITIGATION -j ACCEPT

How can I reset rate limit counter?

Edit: tried sudo iptables -Z, but following error is thrown.

$ sudo iptables -Z
[sudo] password for pi:
iptables v1.8.2 (nf_tables):  RULE_REPLACE failed (Invalid argument): rule in chain INPUT

已采纳解答

原帖链接 · anx · CC BY-SA 4.0

To reset the -m recent --name SSH data:

echo / | sudo tee /proc/net/xt_recent/SSH

From man 8 iptables-extensions, section "recent":

/proc/net/xt_recent/* are the current lists of addresses
 and information about each entry of each list.

Each file in /proc/net/xt_recent/ can be read from to see
 the current list or written two using the following commands to modify the list:

echo +addr >/proc/net/xt_recent/DEFAULT
    to add addr to the DEFAULT list 
echo -addr >/proc/net/xt_recent/DEFAULT
    to remove addr from the DEFAULT list 
echo / >/proc/net/xt_recent/DEFAULT
    to flush the DEFAULT list (remove all entries). 

This is not the same as the per-rule packet/byte counters which can be cleared with iptables -Z.
This is also not the same as the -m limit (which you are using for rate-limiting the logging) or -m hashlimit counters. Those do not offer such proc interface. Possible workarounds:

  1. unloading the module xt_recent/xt_limit/xt_hashlimit will discard the respective associated data
    • only possible while no rules are currently using it
    • needs to be built as a module - unloading builtins is not supported
  2. changing the rules to use a different --name/--hashlimit-name (appending a number will do)
    • not an atomic transaction
    • depending on order of replacement, can momentarily mean in unexpected behaviour

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-04-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。