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

Recent module, what is preferred rcheck or update?

· 52CE 我爱测

Let's say I have the following rules: iptables -P INPUT DROP iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp -m conntrack --ctst…

问题原文

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

Let's say I have the following rules:

iptables -P INPUT DROP
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 
iptables -A INPUT -p tcp -m conntrack --ctstate NEW -m tcp --dport 22 -m recent --set --name counting1 --rsource 
iptables -A INPUT -m recent --update --seconds 60 --hitcount 2 --name counting1 --rsource -j LOG --log-prefix "SSH  ataque " 
iptables -A INPUT -m recent --update --seconds 60 --hitcount 2 --name counting1 --rsource -j RETURN 
-A INPUT -j ACCEPT

I have read the manual but I still don't understand exactly in what cases it's preferred either --rcheck or --update option... does update mean that the hitcount is reset to 0 and restart the (as in the above example) the 60 seconds?

Please bear in mind that these rules are only en example to expose this question.

已采纳解答

原帖链接 · zagrimsan · CC BY-SA 3.0

From the man page of iptables:

   [!] --rcheck
          Check if the source address of the packet is  currently  in  the
          list.

   [!] --update
          Like  --rcheck,  except it will update the "last seen" timestamp
          if it matches.

So, using update will not reset the hitcount, it will (re)set the last seen timestamp. The following is said about --seconds:

   --seconds seconds
          This  option must be used in conjunction with one of --rcheck or
          --update. When used, this will narrow the match to  only  happen
          when  the  address  is  in the list and was seen within the last
          given number of seconds.

That means using --rcheck makes the rule to match only the time interval scecified in the rule (e.g. with --seconds) at a time, while using --update will extend the time interval the rule is being matched if matching packets are encountered during the interval.

So, if there is a matching packet every 45 secs the example rules shown in the question will keep on logging the packets and returning from the chain. OTOH if --rcheck had been used, every second packet would not be matched (as the 60 sec interval for two matching packets has expired).

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

资料来源与适用范围

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

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

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