Différences entre les versions de « Iptables »

De BlaxWiki
Aller à la navigationAller à la recherche
m (a déplacé Iptables doc vers Iptables)
Ligne 2 : Ligne 2 :


[https://wiki.blaxeenprod.com/BENPERSO/doc-manuel/system/Iptables-FR.pdf Tutorial bis]
[https://wiki.blaxeenprod.com/BENPERSO/doc-manuel/system/Iptables-FR.pdf Tutorial bis]
=== Bridge ===
Règles pour filtrer les paquets à travers un linux en bridge
<pre>
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -m state --state NEW -m limit --limit 50/s --limit-burst 100 -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp ! --syn -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp --dport 20 -j ACCEPT
</pre>
=== Nat ===
S'assurer que le module iptables_nat est bien chargé .
<pre>
Pour natter vers le port 80 de la machine 192.168.0.3 : echo 1 > /proc/sys/net/ipv4/ip_forward (active le forward)
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3:80
* regles pour les translations ip privees <---------> ip publiques
-A PREROUTING -d 212.43.236.228 -p tcp -j DNAT --to-destination 192.168.1.8
-A PREROUTING -d 212.43.236.228 -p udp -j DNAT --to-destination 192.168.1.8
-A POSTROUTING -s 192.168.1.8 -j SNAT --to-source 212.43.236.228
-A PREROUTING -d 212.43.236.229 -p tcp -j DNAT --to-destination 192.168.1.9
-A PREROUTING -d 212.43.236.229 -p udp -j DNAT --to-destination 192.168.1.9
-A POSTROUTING -s 192.168.1.9 -j SNAT --to-source 212.43.236.229
Pour autoriser une machine en ip privée à utiliser l'autre machine comme gateway et ainsi pouvoir sortir : echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source xxx.xxx.xxx.xxx (où xxx.xxx.xxx.xxx est l'ip publique de la machine)
<pre>


[[Catégorie:Software]]
[[Catégorie:Software]]

Version du 10 avril 2012 à 16:55

Tutorial très complet (pris sur http://www.linux-france.org/prj/inetdoc/telechargement/iptables-tutorial.pdf)

Tutorial bis


Bridge

Règles pour filtrer les paquets à travers un linux en bridge

-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -m state --state NEW -m limit --limit 50/s --limit-burst 100 -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp ! --syn -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p icmp -j ACCEPT
-A FORWARD -m physdev --physdev-in eth0 -d 212.43.220.38 -p tcp --dport 20 -j ACCEPT 


Nat

S'assurer que le module iptables_nat est bien chargé .


Pour natter vers le port 80 de la machine 192.168.0.3 : echo 1 > /proc/sys/net/ipv4/ip_forward (active le forward)
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3:80

* regles pour les translations ip privees <---------> ip publiques

-A PREROUTING -d 212.43.236.228 -p tcp -j DNAT --to-destination 192.168.1.8
-A PREROUTING -d 212.43.236.228 -p udp -j DNAT --to-destination 192.168.1.8
-A POSTROUTING -s 192.168.1.8 -j SNAT --to-source 212.43.236.228

-A PREROUTING -d 212.43.236.229 -p tcp -j DNAT --to-destination 192.168.1.9
-A PREROUTING -d 212.43.236.229 -p udp -j DNAT --to-destination 192.168.1.9
-A POSTROUTING -s 192.168.1.9 -j SNAT --to-source 212.43.236.229

Pour autoriser une machine en ip privée à utiliser l'autre machine comme gateway et ainsi pouvoir sortir : echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source xxx.xxx.xxx.xxx (où xxx.xxx.xxx.xxx est l'ip publique de la machine)