Exporting Configurations to a File

To keep nftable configurations across boots or to switch from one configuration to another, you can export an nftable in memory to a file.

To export nftable configurations to a file, do the following:
  1. List the rulesets and save the output to a file:

    sudo nft list ruleset > /etc/nftables/<export_file_name>.nft

    In the previous, <export_file_name> is the name of the file for the exported information. This file now contains all the tables, chains, and rules available in memory.

  2. List a table and save the output to a file:

    sudo nft list table <address_family> <table_name> > /etc/nftables/<export_file_name>.nft

    This file now contains a table and all associated chains and rules available in memory.

  3. List a chain and save the output to a file:

    sudo nft list chain <address_family> <table_name> <chain_name> > /etc/nftables/<export_file_name>.nft

    This file now contains a chain in a table and all associated rules within the chain available in memory.

  4. Ensure the files included in /etc/nftables are executable:
    sudo chmod +x /etc/nftables/<export_file_name>.nft