0

我正在尝试将一些 iptables 规则转换为 nftables 如果在 30 秒的时间跨度内尝试超过 4 次,我想制定一个阻止连接的规则

我原来的 iptables 规则是:

iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 30 --hitcount 4 --rttl --name SSH -j DROP

如何在 nftables 中执行相同(或等效)操作?

4

2 回答 2

0

据我了解,iptables最近的模块在 nftables 中没有等效模块,但是,您应该能够使用仪表来实现类似的功能。

nft add rule ip filter INPUT tcp dport 22 ct state new meter SSHban { ip saddr and 255.255.255.255 limit rate over 8/minute burst 4 packets } counter drop

记录在这里:https ://wiki.nftables.org/wiki-nftables/index.php/Meters

于 2021-10-12T07:26:10.397 回答
0

我试了几个月,找不到完全匹配的。但是我有一个解决方法。

sshPort=2222
nft add table ip sshGuard
nft add chain ip sshGuard input { type filter hook input priority 0 \; }
nft add set ip sshGuard denylist { type ipv4_addr \; flags dynamic, timeout \; timeout 5m \; }
nft add set ip sshGuard sshlist { type ipv4_addr \; flags dynamic, timeout \; timeout 5m \; }
nft add rule ip sshGuard input ct state established,related accept
nft add rule ip sshGuard input tcp dport $sshPort ct state new ip saddr @denylist reject
nft add rule ip sshGuard input tcp dport $sshPort ct state new ip saddr @sshlist add @denylist { ip saddr } accept
nft add rule ip sshGuard input tcp dport $sshPort ct state new limit rate over 2/minute burst 3 packets add @sshlist { ip saddr } counter accept
nft list table ip sshGuard

对于新状态,任何新 IP 都将接受大约 5 个连接。如果limit rate被击中,一个新的 IP(不在 中sshlist)有 2 次机会。对于任何一个IP sshlist,只剩下一次机会。对于 中的任何 IP ,任何新连接都将被拒绝,直到它在5 分钟超时denylist后从 中删除。denylist

于 2021-09-14T13:14:36.107 回答