
Ich verwende nat DNAT, um den Datenverkehr auf einem bestimmten Port über einen GRE-Tunnel an einen anderen Centos-Server weiterzuleiten. Allerdings möchte ich die Rate einer Reihe von Rechenzentrums-IPs begrenzen, die ich in einer IPset-Liste „Blacklist“ habe. Damit ist der an den Tunnel ausgegebene Datenverkehr ratenbegrenzt.
Ich habe versucht, die Ratenbegrenzung in allen FORWARD-, INPUT- und OUTPUT-Listen vorzunehmen, jedoch funktioniert die Ratenbegrenzung in keiner davon – vielleicht umgeht das NAT-DNAT sie?
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
Wenn ich die Liste zum Löschen über „iptables -A OUTPUT -m set --match-set blacklist src -j DROP“ hinzufüge, wird der gesamte Datenverkehr gestoppt. Meine IP-Ipset-Liste funktioniert also, nur die Ratenbegrenzung nicht. Kann jemand helfen?
iptables-Ausgabe:
iptables NAT-Ausgabe:
iptables-Regeln
#!/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
Antwort1
Es scheint, dass dies die bessere Regel war - den Verkehr zu stoppen, bevor man durch den GRE-Tunnel über die Begrenzung fährt
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 – um den eingehenden Datenverkehr in /24-Gruppen zu gruppieren