#!/bin/sh # # Fichier d'initialisation des règles iptables # # Nota : ce fichier n'est pas automatiquement utilisé au boot ; # sauvegarder le résultat par iptables-save >/etc/sysconfig/iptables # avant de faire /etc/init.d/iptables restart # # Historique : # YR 02/06/30 : Ajout de la règle de trasnparence pour IP_BELL # YR 02/05/01 : Ajout de règles de retrait de certains logs. # ######## # Variables utiles IP_BELL="62.212.98.250/32" IP_BEAU="192.168.0.0/24" IP_LAN="192.168.0.0/24" IF_LAN="eth1" IP_LO="127.0.0.1" IF_LO="lo" IF_INET="eth0" IPT="/sbin/iptables" KEEPSTATE="-m state --state ESTABLISHED,RELATED" LIMIT3="-m limit --limit 3/minute --limit-burst 3" LIMIT10="-m limit --limit 10/minute --limit-burst 100" ######## # Flush tables ######## $IPT -F $IPT -t nat -F $IPT -t mangle -F ######## # Policy ######## $IPT -P INPUT DROP $IPT -P OUTPUT DROP $IPT -P FORWARD DROP ######## # Définition de chaînes ######## ######## # Règles ######## # IP Forwarding et SNAT de base # Protéger l'accès à Belleville ((NAT avec un filtre pour VPN) # $IPT -t nat -A POSTROUTING -o $IF_INET -d \! $IP_BELL -j MASQUERADE # Installer un NAT de base (sans filtre) $IPT -t nat -A POSTROUTING -o $IF_INET -j MASQUERADE # Autoriser l'accès Belleville en direct sur carotide $IPT -A INPUT -s $IP_BELL -j ACCEPT # Accept everything from/to LAN $IPT -A FORWARD -i $IF_LAN -j ACCEPT $IPT -A INPUT -i $IF_LAN -j ACCEPT $IPT -A OUTPUT -o $IF_LAN -j ACCEPT $IPT -A OUTPUT -j ACCEPT #$IPT -A OUTPUT -s $IP_LAN -d $IP_BELL -j ACCEPT #$IPT -A OUTPUT -s $IP_BELL -d $IP_LAN -j ACCEPT ######## # IPsec ######## # IKE negociation $IPT -A INPUT -p udp --sport 500 --dport 500 -j ACCEPT $IPT -A OUTPUT -p udp --sport 500 --dport 500 -j ACCEPT # ESP encryption $IPT -A INPUT -p 50 -j ACCEPT $IPT -A OUTPUT -p 50 -j ACCEPT # Open as necessary # FTP $IPT -A FORWARD -i $IF_LAN -p tcp --dport 21 -j ACCEPT $IPT -A FORWARD -i $IF_LAN -p tcp --dport 1024:65535 -j ACCEPT $IPT -A OUTPUT -p tcp --dport 21 -j ACCEPT $IPT -A INPUT -p tcp --dport 20 -j ACCEPT # DNS $IPT -A FORWARD -i $IF_LAN -p udp --dport 53 -j ACCEPT $IPT -A OUTPUT -p udp --dport 53 -j ACCEPT # HTTP $IPT -A FORWARD -i $IF_LAN -p tcp --dport 80 -j ACCEPT $IPT -A OUTPUT -p tcp --dport 80 -j ACCEPT # POP3 $IPT -A FORWARD -i $IF_LAN -p tcp --dport 110 -j ACCEPT # identd/auth $IPT -A FORWARD -i $IF_LAN -p tcp --dport 113 -j ACCEPT $IPT -A INPUT -i $IF_INET -p tcp --dport 113 -j ACCEPT $IPT -A OUTPUT -p tcp --sport 113 -j ACCEPT # On accepte tous les paquets loopback $IPT -A INPUT -i $IF_LO -j ACCEPT $IPT -A OUTPUT -o $IF_LO -j ACCEPT # On accepte tous les paquets liés à une connexion établie $IPT -A FORWARD $KEEPSTATE -j ACCEPT $IPT -A INPUT $KEEPSTATE -j ACCEPT ######## # Accept ping within reason ######## $IPT -A FORWARD -p icmp -j ACCEPT # Incoming $IPT -A INPUT -p icmp --icmp-type echo-request $LIMIT3 -j ACCEPT $IPT -A OUTPUT -p icmp --icmp-type echo-reply $LIMIT3 -j ACCEPT # Request $IPT -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT # réponse autorisée par $KEEPSTATE ######## # Apache server on the outside ######## $IPT -A INPUT -p tcp --destination-port 80 -j ACCEPT ######## # DNS ######## $IPT -A OUTPUT -p udp --source-port 53 --destination-port 53 -j ACCEPT ######## # eDonkey2000 ######## $IPT -A INPUT -p tcp --destination-port 4661 -j ACCEPT $IPT -A INPUT -p tcp --source-port 4661 -j ACCEPT $IPT -A OUTPUT -p tcp --destination-port 4661 -j ACCEPT $IPT -A OUTPUT -p tcp --source-port 4661 -j ACCEPT $IPT -A INPUT -p tcp --destination-port 4662 -j ACCEPT $IPT -A INPUT -p tcp --source-port 4662 -j ACCEPT $IPT -A OUTPUT -p tcp --destination-port 4662 -j ACCEPT $IPT -A OUTPUT -p tcp --source-port 4662 -j ACCEPT $IPT -A INPUT -p tcp --destination-port 4665 -j ACCEPT $IPT -A INPUT -p tcp --source-port 4665 -j ACCEPT $IPT -A OUTPUT -p tcp --destination-port 4665 -j ACCEPT $IPT -A OUTPUT -p tcp --source-port 4665 -j ACCEPT $IPT -A OUTPUT -p udp --source-port 4672 --destination-port 4672 -j ACCEPT ######## # Do not log ######## # Broadcasts $IPT -A OUTPUT -p all -d 10.255.255.255 -j DROP $IPT -A INPUT -p all -d 10.255.255.255 -j DROP $IPT -A INPUT -p all -s 213.186.35.33 -j DROP # Multicasts $IPT -A OUTPUT -p all -d 224.0.0.0/4 -j DROP $IPT -A INPUT -p all -d 224.0.0.0/4 -j DROP # 1080: Proxy server explorations (pour des connexions IRC "propres") : $IPT -A INPUT -p tcp --destination-port 1080 -j DROP # 8081: Transparent proxy (pour des connexions IRC "propres") : $IPT -A INPUT -p tcp --destination-port 8081 -j DROP ######## # Log everything else ######## $IPT -A FORWARD $LIMIT10 -j LOG --log-level info --log-prefix IPT_FW__dropped $IPT -A INPUT $LIMIT10 -j LOG --log-level info --log-prefix IPT_IN__dropped $IPT -A OUTPUT $LIMIT10 -j LOG --log-level info --log-prefix IPT_OUT_dropped