installation_d_un_serveur_web_sous_debian_gnu_linux
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
installation_d_un_serveur_web_sous_debian_gnu_linux [2022/02/08 21:29] – [Mise en place des règles de base] Benjamin Labomedia | installation_d_un_serveur_web_sous_debian_gnu_linux [2023/04/11 21:49] (Version actuelle) – [Ajout de règles pour, par exemple, transfert de port vers un container] Benjamin Labomedia | ||
---|---|---|---|
Ligne 309: | Ligne 309: | ||
$ ./ | $ ./ | ||
</ | </ | ||
- | ==== Règles de base bien pratiques (script) ==== | ||
- | Toujours dans le même coin sécurisé de votre serveur, par exemple **/ | ||
- | |||
- | <code bash> | ||
- | $ touch firewall-start.sh | ||
- | $ chmod 700 firewall-start.sh | ||
- | </ | ||
- | Dans ce fichier, mettre ce qui suit. Notez que les ports 300 à 3005 sont ouverts pour le FTP car nous utilisons VSFTPD (voir plus haut) et que nous l' | ||
- | |||
- | <code bash> | ||
- | #!/bin/sh | ||
- | |||
- | #---------- | ||
- | # Load needed modules | ||
- | #---------- | ||
- | modprobe ip_conntrack_ftp | ||
- | modprobe ip_nat_ftp | ||
- | |||
- | #---------- | ||
- | # Local loop | ||
- | #---------- | ||
- | iptables -A INPUT -i lo -j ACCEPT | ||
- | iptables -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT | ||
- | iptables -A OUTPUT -o lo -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # Connexions already established | ||
- | #---------- | ||
- | iptables -A INPUT -m state --state ESTABLISHED, | ||
- | iptables -A OUTPUT -m state --state ESTABLISHED, | ||
- | |||
- | #---------- | ||
- | # NTP (123) | ||
- | #---------- | ||
- | iptables -A OUTPUT -p udp --dport 123 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # NetBios (137) | ||
- | #---------- | ||
- | iptables -A INPUT -p udp --sport 137 -j ACCEPT | ||
- | iptables -A OUTPUT -p udp --dport 137 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # PING | ||
- | #---------- | ||
- | iptables -A INPUT -p icmp --icmp-type 8 -m state --state NEW, | ||
- | iptables -A OUTPUT -p icmp --icmp-type 8 -m state --state NEW, | ||
- | |||
- | #---------- | ||
- | # DNS (53) | ||
- | #---------- | ||
- | # UDP | ||
- | iptables -A INPUT -i eth0 -p udp --sport 53 -m state --state ESTABLISHED -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p udp --dport 53 -m state --state NEW, | ||
- | # TCP | ||
- | iptables -A INPUT -i eth0 -p tcp --sport 53 -m state --state ESTABLISHED -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --dport 53 -m state --state NEW, | ||
- | |||
- | #---------- | ||
- | # WHOIS (43) | ||
- | #---------- | ||
- | iptables -A OUTPUT -p tcp --dport 43 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # SSH (22022) | ||
- | #---------- | ||
- | # Incoming (22022) | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 22022 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 22022 -m state --state ESTABLISHED -j ACCEPT | ||
- | # Outgoing (22) | ||
- | iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW, | ||
- | # Outgoing (22022) | ||
- | iptables -A INPUT -i eth0 -p tcp --sport 22022 -m state --state ESTABLISHED -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --dport 22022 -m state --state NEW, | ||
- | |||
- | #---------- | ||
- | # HTTP (80) | ||
- | #---------- | ||
- | # Incoming | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT | ||
- | # Outgoing | ||
- | iptables -A INPUT -p tcp --sport 80 -j ACCEPT | ||
- | iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # HTTPS (443) | ||
- | #---------- | ||
- | # Incoming | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT | ||
- | # Outgoing | ||
- | iptables -A INPUT -p tcp --sport 443 -j ACCEPT | ||
- | iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # FTP (21, | ||
- | #---------- | ||
- | # Incoming | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 21 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT | ||
- | |||
- | iptables -A INPUT -i eth0 -p tcp --dport 3000:3005 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 3000:3005 -m state --state ESTABLISHED, | ||
- | iptables -A INPUT -i eth0 -p udp --dport 3000:3005 -m state --state NEW, | ||
- | iptables -A OUTPUT -o eth0 -p udp --sport 3000:3005 -m state --state ESTABLISHED, | ||
- | |||
- | #---------- | ||
- | # SMTP (25,587) | ||
- | #---------- | ||
- | # Incoming | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 25 -j ACCEPT | ||
- | iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --sport 587 -j ACCEPT | ||
- | # Outgoing | ||
- | iptables -A INPUT -i eth0 -p tcp --sport 25 -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --dport 25 -j ACCEPT | ||
- | iptables -A INPUT -i eth0 -p tcp --sport 587 -j ACCEPT | ||
- | iptables -A OUTPUT -o eth0 -p tcp --dport 587 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # MUNIN (4949) | ||
- | #---------- | ||
- | iptables -A OUTPUT -p tcp --dport 4949 -j ACCEPT | ||
- | |||
- | #---------- | ||
- | # Logs | ||
- | #---------- | ||
- | iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix " | ||
- | iptables -A OUTPUT -m limit --limit 5/min -j LOG --log-prefix " | ||
- | |||
- | #---------- | ||
- | # DROP everything else | ||
- | #---------- | ||
- | iptables -A INPUT -j DROP | ||
- | iptables -A OUTPUT -j DROP | ||
- | iptables -A FORWARD -j DROP | ||
- | |||
- | #---------- | ||
- | # Reload Fail2Ban (si installé) | ||
- | #---------- | ||
- | service fail2ban restart | ||
- | |||
- | exit 0 | ||
- | </ | ||
- | Et pour démarrer ce script automatiquement au (re)démarrage de votre serveur, modifier le fichier **/ | ||
- | |||
- | <code bash> | ||
- | / | ||
- | </ | ||
==== Script pour redémarrer le Firewall avec toutes les règles ==== | ==== Script pour redémarrer le Firewall avec toutes les règles ==== | ||
Ligne 551: | Ligne 399: | ||
- | {{tag>bj web serveur}} | + | {{tag>futuretic |
installation_d_un_serveur_web_sous_debian_gnu_linux.1644355766.txt.gz · Dernière modification : 2022/02/08 21:29 de Benjamin Labomedia