Fail2ban: Forskjell mellom sideversjoner
Innhold lagt til Slettet innhold
m (formattering) |
(La til ny og bedre løsning :)) |
||
Linje 1: | Linje 1: | ||
== Ny og bedre måte == |
|||
Bruker faktisk ikke fail2ban, men ipset og iptables. |
|||
Mulig man må lage et ipset med 'ipset create countries hash:net' først. |
|||
<syntaxhighlight lang="bash"> |
|||
#/root/iptables/ban-ip-countries.sh |
|||
COUNTRIES=('cn' 'ru') |
|||
ipset flush countries |
|||
for i in "${COUNTRIES[@]}"; do |
|||
echo "Ban IP of country ${i}" |
|||
for IP in $(wget -O - https://www.ipdeny.com/ipblocks/data/countries/${i}.zone) |
|||
do |
|||
ipset add countries $IP |
|||
done |
|||
done |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="bash"> |
|||
iptables -t filter -I INPUT -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable |
|||
iptables -t filter -I FORWARD -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable |
|||
iptables -t filter -I DOCKER-USER -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable |
|||
</syntaxhighlight> |
|||
For å slette regel kjør -D i stedet for -I. |
|||
== Utdatert måte == |
|||
Kontekst: https://github.com/CloudburstMC/Network/security/advisories/GHSA-6h3m-c6fv-8hvh |
Kontekst: https://github.com/CloudburstMC/Network/security/advisories/GHSA-6h3m-c6fv-8hvh |
||
Sideversjonen fra 14. apr. 2024 kl. 22:55
Ny og bedre måte
Bruker faktisk ikke fail2ban, men ipset og iptables.
Mulig man må lage et ipset med 'ipset create countries hash:net' først.
#/root/iptables/ban-ip-countries.sh
COUNTRIES=('cn' 'ru')
ipset flush countries
for i in "${COUNTRIES[@]}"; do
echo "Ban IP of country ${i}"
for IP in $(wget -O - https://www.ipdeny.com/ipblocks/data/countries/${i}.zone)
do
ipset add countries $IP
done
done
iptables -t filter -I INPUT -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable
iptables -t filter -I FORWARD -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable
iptables -t filter -I DOCKER-USER -p udp -m set --match-set countries src -j REJECT --reject-with icmp-host-unreachable
For å slette regel kjør -D i stedet for -I.
Utdatert måte
Kontekst: https://github.com/CloudburstMC/Network/security/advisories/GHSA-6h3m-c6fv-8hvh
Selv om problemet ble patchet i GeyserMC blir konsollen allikevel flooda:
I et forsøk på å unngå dette er det forsøkt å satt opp fail2ban. Siden serveren kjører i docker må det tas ekstra hensyn, se https://tkaefer.de/blog/2021/12/07/follow-up-docker-and-fail2ban-how-i-solved-it-for-me/ - /etc/fail2ban/actions.d/iptables-mangle-allports-ipset.conf og /usr/local/bin/ipset-fail2ban.sh er hentet derfra.
Relevante filer
# /etc/fail2ban/filter.d/minecraft.comf
[Definition]
failregex = ^\[.*INFO\]: \[Geyser-Spigot\] \/<HOST>:.* tried to connect\!$
ignoreregex =
#/etc/fail2ban/jail.d/minecraft.conf
[minecraft]
enabled = true
findtime = 300
filter = minecraft
logpath = /home/gamer/minecraft-server/data/logs/latest.log
bantime = 4w
ignoreip = 192.168.10.0/24
protocol = udp
banaction = iptables-mangle-allports-ipset[name="minecraft"]
Kommandoer
fail2ban-client status minecraft