Y'a compliqué et compliqué 😉
https://upandclear.org/2016/03/15/iptablesipset-acces-portsservices-selon-ip-protections-diverses-et-blocage-ip-chinoises-noracism/
https://upandclear.org/2016/06/25/iptables-faut-pas-en-avoir-peur-regles-openvpn-secu/
Bref... voici le boulot mâché.
sudo nano /etc/iptables.firewall.rules
Y mettre ceci, après avoir modifié les services, ports et IP
*filter
# Purge des regles IPtables
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P FORWARD ACCEPT
-F
-X
# Regles de base
# Autorisation de tout trafic sortant
-P OUTPUT ACCEPT
# Rejeter tout le trafic entrant sauf regles qui suivent
-P INPUT DROP
# Autorisation des connexions entrantes deja etablies
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Autorisation des connexions internes (loopback)
-A INPUT -i lo -j ACCEPT
# Autorisation entrantes des services
# SSH / autorisation selon IP VPN personnel 1
-I INPUT -p tcp -s xx.xx.xx.xx --dport 22 -j ACCEPT
# SyncThing WebAdmin
-I INPUT -p tcp -s xx.xx.xx.xx --dport xx -j ACCEPT
# SyncThing
-I INPUT -p tcp --dport xx -j ACCEPT
# Medusa
-I INPUT -p tcp -s xx.xx.xx.xx --dport 8081 -j ACCEPT
# SABnzbd+
-I INPUT -p tcp -s xx.xx.xx.xx --dport 8080 -j ACCEPT
# Radarr
-I INPUT -p tcp -s xx.xx.xx.xx --dport 7878 -j ACCEPT
# Jackett
-I INPUT -p tcp -s xx.xx.xx.xx --dport 9117 -j ACCEPT
# Serveurs Web
-I INPUT -p tcp -s xx.xx.xx.xx --dport 80 -j ACCEPT
-I INPUT -p tcp -s xx.xx.xx.xx --dport 443 -j ACCEPT
# Autorisation rTorrent
-I INPUT -p tcp --dport xx -j ACCEPT
# Ping depuis VPN NL2
-I INPUT -p icmp -s xx.xx.xx.xx --icmp-type echo-request -j ACCEPT
# Regles de protection + logs
# DROP paquets autres que SYN
-A INPUT -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
# DROP paquets invalides
-A INPUT -m conntrack --ctstate INVALID -j DROP
# DROP paquets incomplets
-A INPUT -f -j DROP
# DROP NULL
-A INPUT -p tcp --tcp-flags ALL NONE -j DROP
# DROP XMAS
-A INPUT -p tcp --tcp-flags ALL ALL -j DROP
# DROP SYNFIN
-A INPUT -p tcp --tcp-flags ALL SYN,FIN -j DROP
# DROP FIN scan
-A INPUT -p tcp --tcp-flags ALL FIN -j DROP
# DROP SYN RST
-A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
# DROP NMAP XMAS
-A INPUT -p tcp --tcp-flags ALL URG,PSH,FIN -j DROP
# DROP NMAP
-A INPUT -p tcp --tcp-flags ALL URG,PSH,SYN,FIN -j DROP
# DROP SYN FLOOD
-N SYN-FLOOD
-A SYN-FLOOD -m limit --limit 1/sec --limit-burst 4 -j RETURN
-A SYN-FLOOD -j DROP
# DROP port scans
-N PORT-SCAN
-A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -j PORT-SCAN
-A PORT-SCAN -m limit --limit 1/s --limit-burst 4 -j RETURN
-A PORT-SCAN -j DROP
# Blocage IP attaque 24h
-A INPUT -m recent --name DUMBASS --rcheck --seconds 86400 -j DROP
-A FORWARD -m recent --name DUMBASS --rcheck --seconds 86400 -j DROP
# Levee du blocage
-A INPUT -m recent --name DUMBASS --remove
-A FORWARD -m recent --name DUMBASS --remove
# Logging des paquets entrants droppes
-N LOGGING
-A INPUT -j LOGGING
-A LOGGING -m limit --limit 3/min -j LOG --log-prefix "IPtables_DROP: " --log-level 7
-A LOGGING -j DROP
COMMIT
sudo iptables-restore < /etc/iptables.firewall.rules
sudo apt install iptables-persistent