Philb
Philb

Reputation: 11

Migrate NFTables settings to other machines

I'm looking for a solution to migrate my NFTables settings automatically on a day to day basis to other linux computers in my network. I was thinking about writing a script to pull the settings from my computer and somehow overwrite the old nftables.conf file on the other computer(B) in the network. Computer B would execute the script via cron every day. At least that's my initial thought since i couldn't find any tools that can do this on their own. Am i missing the point here, is it even possible the way i want to do it or are there already solutions for this task?

Thanks in advance

Upvotes: 1

Views: 1465

Answers (1)

Zzz0_o
Zzz0_o

Reputation: 598

You can export or store your current ruleset in a file using export/list command then you can import that ruleset file using -f option.

For Example:

$ nft list ruleset > your_nftables_ruleset_file

and then

$ nft -f your_nftables_ruleset_file

For more info, you can refer this nftables wiki page:
https://wiki.nftables.org/wiki-nftables/index.php/Operations_at_ruleset_level

Alternatively, you can export and import ruleset in json format using
$ nft export vm json > rules.json and then$ cat rules.json | nft import vm json (Note: This feature is yet come in mainline) If you are curious you can use this patch https://patchwork.ozlabs.org/project/netfilter-devel/list/?series=16814 :)

Upvotes: 1

Related Questions