par grimms » 10 Nov 2003 08:18
Salut
<BR>Faut jouer avec les regles iptables
<BR>
<BR><!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-2>En réponse à:</font><HR></TD></TR><TR><TD><FONT SIZE=-2><BLOCKQUOTE>
<BR>#!/bin/sh
<BR># Script "fire.sh"
<BR># Fichier contenant les regles de filtrage iptables
<BR>
<BR>
<BR>
<BR>IPTABLES=/sbin/iptables
<BR>#interface internet eth1 pour les modem usb non sagem ppp0
<BR>EXTERNAL_IF="eth1"
<BR>
<BR># REMISE Ã ZERO des regles de filtrage
<BR>$IPTABLES -F
<BR>$IPTABLES -t nat -F
<BR>
<BR>
<BR>#Politique par défaut on fait le mort pc invisible
<BR>$IPTABLES -P INPUT DROP
<BR>$IPTABLES -P OUTPUT DROP
<BR>$IPTABLES -P FORWARD DROP
<BR>
<BR>#Traffic Local tous est authoriser
<BR>$IPTABLES -A INPUT -i lo -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o lo -j ACCEPT
<BR>$IPTABLES -A FORWARD -s 192.168.1.0/24 -j ACCEPT
<BR>
<BR>
<BR>#eth0 reseau local authoriser (les pc client on acces a tous les port avec cette config donc un troyen passera)
<BR>$IPTABLES -A INPUT -i eth0 -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o eth0 -j ACCEPT
<BR>$IPTABLES -A FORWARD -i eth0 -j ACCEPT
<BR>$IPTABLES -A FORWARD -o eth0 -j ACCEPT
<BR>
<BR>#Log on logue tous inconvenient si on as pas d'interface graphique on a les info qui s'ecrive dans la console active
<BR>$IPTABLES -N LOG_DROP
<BR>$IPTABLES -A LOG_DROP -j LOG --log-prefix "[Firewall] "
<BR>$IPTABLES -A LOG_DROP -j DROP
<BR>
<BR>
<BR>#Acces au web
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp -m multiport --sports 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp -m multiport --dports 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#FTP passif
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Acces au smtp pop imap
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp -m multiport --sports smtp,pop3,imap2 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp -m multiport --dports smtp,pop3,imap2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Acces au DNS
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --sport 53 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p udp --sport 53 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p udp --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Ping
<BR>$IPTABLES -A OUTPUT -p icmp -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
<BR>$IPTABLES -A INPUT -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT
<BR>$IPTABLES -A INPUT -p icmp -m state --state NEW -m limit --limit 10/min -j ACCEPT
<BR>
<BR>
<BR>#NTP
<BR># $IPTABLES -A INPUT -i $EXTERNAL_IF -p udp --sport ntp -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR># $IPTABLES -A OUTPUT -o $EXTERNAL_IF -p udp --dport ntp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>
<BR>#amsn
<BR>#le port 6891 6892 etc permete le transfert di fichier
<BR>$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport 6891 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --dport 6891 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>#port indispensable pour ce connecter
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --dport 1863 -d 0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport 38889 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#SSL
<BR>#$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --sport 443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --dport 443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>###### SERVEUR ######
<BR>
<BR>#Serveur www
<BR>#$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport www -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>#$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport www -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>
<BR>#Serveur SSH vers un ip fixe
<BR># $IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport ssh -d 192.168.1.2 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR># $IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport ssh -s 192.168.1.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Serveur smtp
<BR># $IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport smtp -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR># $IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport smtp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Serveur pop
<BR># $IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport pop3 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR># $IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport pop3 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Serveur imap
<BR>#$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport imap2 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>#$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport imap2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>
<BR>#Serveur FTP
<BR>#$IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp -m multiport --sports ftp,ftp-data -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR>#$IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp -m multiport --dports ftp,ftp-data -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>#Serveur MySQL pour IP fixes
<BR># $IPTABLES -A OUTPUT -o $EXTERNAL_IF -p tcp --sport mysql -d 192.168.1.2 -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR># $IPTABLES -A INPUT -i $EXTERNAL_IF -p tcp --dport mysql -s 192.168.1.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
<BR>
<BR>
<BR>#Partage de connection
<BR>$IPTABLES -A POSTROUTING -t nat -o $EXTERNAL_IF -j MASQUERADE
<BR>
<BR>
<BR># Autoriser le forward pour le partage internet
<BR> echo 1 > /proc/sys/net/ipv4/ip_forward
<BR>
<BR>#transfert de port
<BR>#/sbin/iptables -t nat -A PREROUTING -p tcp --dport 2346 -j DNAT --to-destination 192.168.1.2:2346
<BR>
<BR>/sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
<BR>
<BR>#On fout tout dans le syslog
<BR>$IPTABLES -A FORWARD -j LOG_DROP
<BR>$IPTABLES -A INPUT -j LOG_DROP
<BR>$IPTABLES -A OUTPUT -j LOG_DROP
<BR> </BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->
<BR>
<BR>Voila le script que j'utilise
<BR>je pense qu'ici d'autre t'en fourniron un mieux mais il fonctionne
<BR>eth1 est mon interface internet
<BR>eth0 pour mon local
<BR>
<BR>a toi de prendre ce qui t'interesse