在透過 GRE 隧道發送之前,對 ipset 清單中的 UDP 流量進行速率限制 IP

在透過 GRE 隧道發送之前,對 ipset 清單中的 UDP 流量進行速率限制 IP

我正在使用 nat DNAT 透過 GRE 隧道將某個連接埠上的流量轉送到另一台 Centos 伺服器,但我想對 ipset 清單「黑名單」中的一堆資料中心 IP 進行速率限制。從而對輸出到隧道的流量進行速率限制。

我已嘗試在所有 FORWARD、INPUT 和 OUTPUT 列表中進行速率限制,但是速率限制在其中任何一個列表中都不起作用 - 也許 nat DNAT 會繞過它?

iptables -A INPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A FORWARD -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A OUTPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP

如果我透過「iptables -A OUTPUT -m set --match-set blacklist src -j DROP」添加要刪除的列表,它會停止所有流量,所以我的IP ipset 列表正在工作,只是沒有速率限制,任何人都可以幫忙?

iptables 輸出:

iptables 輸出

iptables NAT 輸出:

iptables nat 輸出

iptables規則


#!/bin/sh
iptables -F
sudo iptables -t nat -F
iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -t raw -F
sudo iptables -t raw -X
sudo iptables -t security -F
sudo iptables -t security -X
sudo iptables -F
sudo iptables -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT

iptables -A INPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A FORWARD -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP
iptables -A OUTPUT -m set --match-set blacklist src -p udp --dport 30000 -m hashlimit --hashlimit 10/min --hashlimit-name ratelimithash -j DROP

iptables -t nat -A POSTROUTING -s 192.168.168.0/30 ! -o gre+ -j SNAT --to-source 20&&&&&&&&&&&&

iptables -A INPUT -s 192.168.168.2/32 -j ACCEPT

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


iptables -A INPUT -p gre -j ACCEPT
iptables -A OUTPUT -p gre -j ACCEPT

iptables -t nat -A PREROUTING -d 20&&&&&&&&&&&& -p udp --dport 30000 -j DNAT --to-destination 192.168.168.2


iptables -A OUTPUT -j DROP
iptables -P INPUT DROP

答案1

看來這是更好的規則 - 在超過 GRE 隧道限制之前停止流量

iptables -t mangle -A PREROUTING -p udp --dport 30000 -m set --match-set blacklist src -m hashlimit --hashlimit-mode srcip --hashlimit-srcmask 24 --hashlimit-above 100/sec --hashlimit-name test -j DROP

-hashlimit-srcmask 24 - 將傳入流量分組為 /24 組

相關內容