1
0
Fork 0
myserver-configuration/roles/iptables/templates/firewall.j2

90 lines
3.2 KiB
Text
Raw Normal View History

2022-10-25 13:34:44 +02:00
#!/bin/sh
### BEGIN INIT INFO
# Provides: firewall rules
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#Suppression des règles précédentes
2023-05-21 15:19:59 +02:00
/sbin/iptables -F
/sbin/iptables -X
2022-10-25 13:34:44 +02:00
########
# DROP #
########
# Définition du blocage général
2023-05-21 15:19:59 +02:00
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP
2022-10-25 13:34:44 +02:00
# Drop des scans XMAS et NULL
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
/sbin/iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
/sbin/iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
/sbin/iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
2022-10-25 13:34:44 +02:00
##########
# ACCEPT #
##########
# Conservations des connexions déjà établies
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
2022-10-25 13:34:44 +02:00
# Autorisation du loopback (127.0.0.1)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT
2022-10-25 13:34:44 +02:00
# Autorisation des échanges avec le serveur DNS (53)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A OUTPUT -p udp -m udp --dport 53 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT -p udp -m udp --sport 53 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -m tcp --dport 53 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --sport 53 -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
2022-10-25 13:34:44 +02:00
# NTP (123)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p udp --sport 123 -j ACCEPT
/sbin/iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
2022-10-25 13:34:44 +02:00
# HTTP (80)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
2022-10-25 13:34:44 +02:00
2022-12-01 19:42:17 +01:00
# HTTP MATRIX FEDERATION (8448)
# /sbin/iptables -A INPUT -p tcp --dport 8448 -j ACCEPT
# /sbin/iptables -A OUTPUT -p tcp --dport 8448 -j ACCEPT
2022-12-01 19:42:17 +01:00
2022-10-25 13:34:44 +02:00
# HTTPS (443)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
2022-10-25 13:34:44 +02:00
2023-05-21 11:31:41 +02:00
# SSH
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p tcp --dport {{ server.ssh_port }} -j ACCEPT
2023-09-25 22:01:57 +02:00
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT # ACCEPT SSH INPUT THROUGH TRAEFIK
2023-05-21 15:19:59 +02:00
/sbin/iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT # ACCEPT SSH OUTPUT LIKE GIT
2022-10-25 13:34:44 +02:00
# ICMP (Ping)
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -p icmp -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp -j ACCEPT
2022-10-25 13:34:44 +02:00
# Parer les attaques de type Déni de Service
2023-05-21 15:19:59 +02:00
/sbin/iptables -A FORWARD -p tcp --syn -m limit --limit 1/second -j ACCEPT
/sbin/iptables -A FORWARD -p udp -m limit --limit 1/second -j ACCEPT
/sbin/iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
2022-10-25 13:34:44 +02:00
# Parer les scans de ports
2023-05-21 15:19:59 +02:00
/sbin/iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
2023-01-05 20:13:40 +01:00
# Allow all from private network and docker network
2023-05-21 15:19:59 +02:00
/sbin/iptables -A INPUT -j ACCEPT -d 172.17.0.0/16
/sbin/iptables -A OUTPUT -j ACCEPT -d 172.17.0.0/16
/sbin/iptables -A INPUT -j ACCEPT -d 192.168.1.0/24
/sbin/iptables -A OUTPUT -j ACCEPT -d 192.168.1.0/24
2023-09-24 12:28:25 +02:00
# VPN
/sbin/iptables -A INPUT -p udp --dport {{ server.vpn.port }} -j ACCEPT