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 グループにグループ化します

関連情報