Vous n'êtes pas identifié(e).
L'icône rouge permet de télécharger chaque page du wiki visitée au format
PDF et la grise au format ODT →
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | Prochaine révision Les deux révisions suivantes | ||
doc:reseau:iptables-pare-feu-pour-une-passerelle [16/11/2014 07:42] Hypathie [Les règles du pare-feu pas à pas] |
doc:reseau:iptables-pare-feu-pour-une-passerelle [16/11/2014 09:15] Hypathie [Les règles du pare-feu pas à pas] |
||
---|---|---|---|
Ligne 367: | Ligne 367: | ||
iptables -t filter -A FORWARD -i eth0 -o eth1 -s 0.0.0.0/0 -d 192.168.1.0/24 -p\ | iptables -t filter -A FORWARD -i eth0 -o eth1 -s 0.0.0.0/0 -d 192.168.1.0/24 -p\ | ||
tcp -m state --state ESTABLISHED,RELATED -j ACCEPT | tcp -m state --state ESTABLISHED,RELATED -j ACCEPT | ||
+ | </code> | ||
- | iptables -t filter -A FORWARD -p icmp -j ACCEPT | + | * Ce qui donne : |
+ | <code root>iptables -L</code> | ||
+ | <code> | ||
+ | Chain INPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | |||
+ | Chain FORWARD (policy DROP) | ||
+ | target prot opt source destination | ||
+ | ACCEPT tcp -- 192.168.1.0/24 anywhere state NEW,RELATED,ESTABLISHED | ||
+ | ACCEPT tcp -- anywhere 192.168.1.0/24 state RELATED,ESTABLISHED | ||
+ | |||
+ | Chain OUTPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
</code> | </code> | ||
+ | > La navigation web fonctionne | ||
+ | > Le ping vers google et vers 192.168.0.22 est bloqué car on a autorisé seulement tcp | ||
- | <note tip> | + | * On ajoute une autorisation pour icmp : |
- | **__Quelques exlications :__** | + | |
- | * __Sans suivi de connexion__ : | + | <code root> |
+ | iptables -t filter -A FORWARD -p icmp -j ACCEPT | ||
+ | </code> | ||
- | iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT | + | * Ce qui donne : |
- | iptables -A FORWARD -o eth1 -i eth0 -j ACCEPT | + | |
- | > On autorise tout passage de eth1 à eth0 et de eth0 à eth1 | + | <code>iptables -L</code> |
+ | <code> | ||
+ | Chain INPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
- | * __Avec suivi de connexion__ : | + | Chain FORWARD (policy DROP) |
+ | target prot opt source destination | ||
+ | ACCEPT tcp -- 192.168.1.0/24 anywhere state NEW,RELATED,ESTABLISHED | ||
+ | ACCEPT tcp -- anywhere 192.168.1.0/24 state RELATED,ESTABLISHED | ||
+ | ACCEPT icmp -- anywhere anywhere | ||
- | iptables -t filter -A FORWARD -i eth1 -o eth0 -s 192.168.1.0/24 -d 0.0.0.0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT | + | Chain OUTPUT (policy ACCEPT) |
- | iptables -t filter -A FORWARD -i eth0 -o eth1 -s 0.0.0.0/0 -d 192.168.1.0/24 -m state --state ESTABLISHED,RELATED -j ACCEPT | + | target prot opt source destination |
+ | </code> | ||
- | > On autorise tout passage avec suivi de connexion de eth1 à eth0 et inversement, en précisant les sous-réseaux. | + | > Le web et le ping fonctionne : |
- | </note> | + | |
- | * On vérifie si le ping fonctionne de la machine A vers la machine B : | + | * De la machine A vers la machine B : |
<code user> | <code user> | ||
ping 192.168.1.2 | ping 192.168.1.2 | ||
Ligne 403: | Ligne 426: | ||
:-D | :-D | ||
- | * Et de la machine B vers la machine A : | + | * De la machine B vers la machine A : |
<code user> | <code user> | ||
ping 192.168.0.22</code> | ping 192.168.0.22</code> | ||
Ligne 417: | Ligne 440: | ||
8-) | 8-) | ||
- | * Pour voir ce qu'on a fait : | + | <note tip> |
- | <code root>iptables -L -t nat && iptables -L</code> | + | |
+ | **__Quelques exlications :__** | ||
+ | |||
+ | * __On autorise toute connexion pour le LAN__ | ||
+ | |||
+ | iptables -A FORWARD -i eth1 -j ACCEPT | ||
+ | iptables -A FORWARD -o eth1 -j ACCEPT | ||
+ | |||
+ | iptables -L | ||
+ | Chain INPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | Chain FORWARD (policy DROP) | ||
+ | target prot opt source destination | ||
+ | ACCEPT all -- anywhere anywhere | ||
+ | ACCEPT all -- anywhere anywhere | ||
+ | Chain OUTPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | |||
+ | > Ce qui entre ''-i'' et ce qui sort ''-o'' | ||
+ | > La navigation internet depuis un ordi du réseau 192.168.1.0/24 est possible | ||
+ | > ping de l'un de ces ordi vers google est ok | ||
+ | |||
+ | * __Sans suivi de connexion__ : | ||
+ | |||
+ | iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT | ||
+ | iptables -A FORWARD -o eth1 -i eth0 -j ACCEPT | ||
+ | |||
+ | > On constate que sans préciser de protocole ni de réseau, cela revient au même que précédemment | ||
+ | |||
+ | iptables -L | ||
+ | Chain INPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | Chain FORWARD (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | ACCEPT all -- anywhere anywhere | ||
+ | ACCEPT all -- anywhere anywhere | ||
+ | Chain OUTPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | |||
+ | > On autorise le passage de eth1 à eth0 et de eth0 à eth1 | ||
+ | |||
+ | * __Avec suivi de connexion__ : | ||
+ | |||
+ | iptables -t filter -A FORWARD -i eth1 -o eth0 -s 192.168.1.0/24 -d 0.0.0.0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT | ||
+ | iptables -t filter -A FORWARD -i eth0 -o eth1 -s 0.0.0.0/0 -d 192.168.1.0/24 -m state --state ESTABLISHED,RELATED -j ACCEPT | ||
+ | |||
+ | > On autorise le passage de tous protocoles avec suivi de connexion, de eth1 à eth0, et inversement, en précisant les réseaux source et destination. | ||
+ | |||
+ | iptables -L | ||
+ | Chain INPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | Chain FORWARD (policy DROP) | ||
+ | target prot opt source destination | ||
+ | ACCEPT all -- 192.168.1.0/24 anywhere state NEW,RELATED,ESTABLISHED | ||
+ | ACCEPT all -- anywhere 192.168.1.0/24 state RELATED,ESTABLISHED | ||
+ | Chain OUTPUT (policy ACCEPT) | ||
+ | target prot opt source destination | ||
+ | |||
+ | > Là encore la navigation est possible pour un ordi du sous-réseau 192.168.1.0/24 | ||
+ | > Et le ping fonctionne vers google et l'ordi 192.168.0.22 sans besoin d'ajouter de règle imcp car on a autorisé TOUS les protocoles | ||
+ | </note> | ||
====Dépendance du NAT et des chaînes FILTER sur l'interface interne (eth1)==== | ====Dépendance du NAT et des chaînes FILTER sur l'interface interne (eth1)==== |