Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
150-cpl-nftables:500-nouveautes [le 20/06/2025 à 14:46] – supprimée - modification externe (Date inconnue) 127.0.0.1 | 150-cpl-nftables:500-nouveautes [le 20/06/2025 à 14:46] (Version actuelle) – ↷ Page déplacée de 135nftables:500-nouveautes à 150-cpl-nftables:500-nouveautes prof | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Quelques nouveautés en vrac ====== | ||
+ | ===== Persistance ===== | ||
+ | Avec '' | ||
+ | ===== Scripts ===== | ||
+ | le service '' | ||
+ | ==== Insérer des commentaires ==== | ||
+ | Il suffit de commencer la ligne par un " | ||
+ | # ceci est un commentaire | ||
+ | ==== Définir des variables ==== | ||
+ | des choses simples comme: | ||
+ | define ifLan = enp7s0 | ||
+ | define ifWan = enp1s0 | ||
+ | Ce qui nous permettra de rendre les règles bien plus lisibles. | ||
+ | Aussi des " | ||
+ | define open_dns = {208.67.222.123, | ||
+ | ==== Exemple ==== | ||
+ | Supposons que nous voulions empêcher les clients de notre lan (192.168.61.0/ | ||
+ | < | ||
+ | # | ||
+ | |||
+ | <span class=" | ||
+ | <span class=" | ||
+ | define ifWan = enp1s0 | ||
+ | define open_dns = {208.67.222.123, | ||
+ | |||
+ | table ip nat { | ||
+ | chain PREROUTING { | ||
+ | type nat hook prerouting priority -100; policy accept; | ||
+ | } | ||
+ | |||
+ | chain INPUT { | ||
+ | type nat hook input priority 100; policy accept; | ||
+ | } | ||
+ | |||
+ | chain POSTROUTING { | ||
+ | type nat hook postrouting priority 100; policy accept; | ||
+ | oifname <span class=" | ||
+ | } | ||
+ | |||
+ | chain OUTPUT { | ||
+ | type nat hook output priority -100; policy accept; | ||
+ | } | ||
+ | } | ||
+ | table ip filter { | ||
+ | chain INPUT { | ||
+ | type filter hook input priority 0; policy accept; | ||
+ | iifname " | ||
+ | iifname <span class=" | ||
+ | } | ||
+ | |||
+ | chain FORWARD { | ||
+ | type filter hook forward priority 0; policy accept; | ||
+ | <span class=" | ||
+ | ip daddr <span class=" | ||
+ | iifname <span class=" | ||
+ | iifname <span class=" | ||
+ | } | ||
+ | |||
+ | chain OUTPUT { | ||
+ | type filter hook output priority 0; policy accept; | ||
+ | oifname " | ||
+ | oifname <span class=" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Bien entendu, une fois ce script exécuté, '' | ||
+ | ===== Éclatement ===== | ||
+ | Dans le cas où nous aurions un très grand nombre de chaînes et de règles dans ces chaînes, il serait alors possible de créer par exemple un fichier par chaîne et de les faire lire séquentiellement par ''/ | ||
+ | Création d'un répertoire ''/ | ||
+ | mkdir / | ||
+ | Création d'un fichier ''/ | ||
+ | # | ||
+ | # include all files in a given directory using an absolute path | ||
+ | include "/ | ||
+ | Les fichiers du répertoire ''/ | ||
+ | Nous pouvons donc créer dans ''/ | ||
+ | # Pour rendre les règles plus lisibles | ||
+ | define ifLan = enp7s0 | ||
+ | define ifWan = enp1s0 | ||
+ | define open_dns = {208.67.222.123, | ||
+ | un fichier '' | ||
+ | < | ||
+ | table ip nat { | ||
+ | chain PREROUTING { | ||
+ | type nat hook prerouting priority -100; policy accept; | ||
+ | } | ||
+ | |||
+ | chain INPUT { | ||
+ | type nat hook input priority 100; policy accept; | ||
+ | } | ||
+ | |||
+ | chain POSTROUTING { | ||
+ | type nat hook postrouting priority 100; policy accept; | ||
+ | oifname $ifWan counter packets 1 bytes 76 masquerade | ||
+ | } | ||
+ | |||
+ | chain OUTPUT { | ||
+ | type nat hook output priority -100; policy accept; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | et un fichier '' | ||
+ | < | ||
+ | table ip filter { | ||
+ | chain INPUT { | ||
+ | type filter hook input priority 0; policy accept; | ||
+ | iifname " | ||
+ | iifname $ifLan counter packets 0 bytes 0 accept | ||
+ | } | ||
+ | |||
+ | chain FORWARD { | ||
+ | type filter hook forward priority 0; policy accept; | ||
+ | # open_dns ne passera pas ! | ||
+ | ip daddr $open_dns counter packets 0 bytes 0 drop | ||
+ | iifname $ifLan oifname $ifWan ct state established, | ||
+ | iifname $ifWan oifname $ifLan ct state established, | ||
+ | } | ||
+ | |||
+ | chain OUTPUT { | ||
+ | type filter hook output priority 0; policy accept; | ||
+ | oifname " | ||
+ | oifname $ifLan counter packets 0 bytes 0 accept | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Je vous laisse vérifier que ça fonctionne. | ||
+ | |||
+ | Nous pouvons nous douter que '' |
Quelques nouveautés en vrac: Dernière modification le: 01/01/1970 à 00:00 par