Bannière
visitor@aschnoebelen.fr:~/2023/07/06/aide-memoire-nftable$ login_

Aide mémoire nftable

  Le 6 juillet 2023     Aurélien Schnoebelen     #linux#sécurité  

Mémo pour récapituler les commandes à utiliser pour gérer nftables sous debian.

Ce mémo va être réécrit prochainement

1. Types de tables

  • ip
  • ip6
  • inet
  • arp
  • bridge
  • netdev

2. Créer une table

nft add table <type> <ma_table>

3. Supprimer une table

nft delete table <type> <ma_table>

4. Ajouter une chaîne

nft add chain <type> <ma_table> <ma_chaîne_1> { type filter hook input priority 0 \; }
nft add chain <type> <ma_table> <ma_chaîne_2> { type filter hook output priority 0 \; } 
nft add chain <type> <ma_table> <ma_chaîne_1> { type nat hook prerouting priority 0 \; }
nft add chain <type> <ma_table> <ma_chaîne_2> { type nat hook postrouting priority 0 \; }  

5. Supprimer une chaîne

nft delete chain <type> <ma_table> <ma_chaîne>

6. Ajouter une règle

nft add rule <type> <ma_table> <ma_chaîne_1> ip daddr <ip-destination> ip saddr <ip-source> accept
nft add rule <type> <ma_table> <ma_chaîne_2> ip daddr <ip-destination> ip saddr <ip-source> accept
nft add rule <type> <ma_table> <ma_chaîne> tcp dport 80 accept
nft add rule <type> <ma_table> <ma_chaîne> drop

7. Lister les règles avec leur id

nft -a list table <type> <ma_table>

8. Supprimer une règle

nft delete rule <type> <ma_table> <ma_chaîne> handle <numéro-id-règle>

9. Ajouter une règle

Après la position :

nft add rule <type> <ma_table> <ma_chaîne_1> position <numéro-id-règle> ip daddr <ip-destination> ip saddr <ip-source> accept

Avant la position :

nft insert rule <type> <ma_table> <ma_chaîne_1> position <numéro-id-règle> ip daddr <ip-destination> ip saddr <ip-source> accept 

10. Autoriser les connexions entrantes si elles ont été initialisées avant

nft add rule <type> <ma_table> <ma_chaîne_input> ct state established,related accept

11. Exporter les données

nft list ruleset > <mon_fichier.txt>