也许有人知道我如何用命令将140万ip添加到iptable:
iptables -I PREROUTING -t raw -d $ipban -j DROP
现在我使用:
while read ipban
do
iptables -I PREROUTING -t raw -d $ipban -j DROP
done < ips.txt但它已经花了20多个小时才加进去。
我的vps非常小,像1gb的内存和1 1vcpu,所以它没有那么快。
我试着做iptables恢复,但我没有什么错误,所以我寻找最快的解决方案。
发布于 2021-08-12 13:17:40
下面的脚本应该可以满足您的需要。注意,您将从其中读取is的文件的名称是脚本中的ips.txt。您可以用自己的文件名替换它。
#!/bin/bash
ip_addresses=$(cat ips.txt)
echo -n "" > iptables_configuration
echo "*raw" >> iptables_configuration
echo ":PREROUTING ACCEPT [0:0]" >> iptables_configuration
echo ":OUTPUT ACCEPT [0:0]" >> iptables_configuration
for i in $ip_addresses
do
echo -A PREROUTING -d $i/32 -j DROP >> iptables_configuration
done
echo "COMMIT" >> iptables_configuration
echo "*filter" >> iptables_configuration
echo ":INPUT ACCEPT [0:0]" >> iptables_configuration
echo ":FORWARD ACCEPT [0:0]" >> iptables_configuration
echo ":OUTPUT ACCEPT [0:0]" >> iptables_configuration
echo "-A INPUT -p tcp -m tcp --dport 25565 --tcp-option 8 --tcp-flags FIN,SYN,RST,ACK SYN -j REJECT --reject-with icmp-port-unreachable" >> iptables_configuration
echo "COMMIT" >> iptables_configuration
cat iptables_configuration | iptables-restore
rm iptables_configuration
iptables -t raw -A PREROUTING -p tcp --dport 25565 -j ACCEPT
iptables -t raw -A PREROUTING -p tcp --dport 25565 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t raw -A PREROUTING -p tcp --dport 25565 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 150 --connlimit-mask 32 --connlimit-saddr -j DROP
iptables -t raw -A PREROUTING -p tcp --dport 25565 --tcp-flags FIN,SYN,RST,ACK SYN -m connlimit --connlimit-above 10 --connlimit-mask 32 --connlimit-saddr -j DROP您所要做的就是执行ips.txt文件所在的脚本。其余的将由脚本处理。
https://askubuntu.com/questions/1357552
复制相似问题