Introduction to nftables on Linux

Comment on Mastodon

Introduction

Linux kernel has an integrated firewall named netfilter, but you manipulate it through command lines such as the good old iptables, or nftables which will eventually superseed iptables.

Today, I'll share my experience in using nftables to manage my Linux home router, and my workstation.

I won't explain much in this blog post because I just want to introduce nftables and show what it looks like, and how to get started.

I added comments in my configuration files, I hope it's enough to get a grasp and make you curious to learn about nftables if you use Linux.

Configurations

nftables works by creating a file running `nft -f` in the shebang, this allows atomic replacement of the ruleset if it's valid.

Depending on your system, you may need to run the script at boot, but for instance on Gentoo, a systemd service is provided to save rules upon shutdown and restore them at boot.

Router

Workstation

Some commands

If you need to operate a firewall using nftables, you may use `nft` to add/remove rules on the go instead of using the script with the ruleset.

However, let me share a small cheatsheet of useful commands:

List rules

If you need to display the current rules in use:

Flush rules

If you want to delete all the rules, just use:

Going further

If you want to learn more about nftables, there is the excellent man page of the command `nft`.

I used some resources from Arch Linux and Gentoo that you may also enjoy:

Gentoo Wiki: Nftables

Gentoo Wiki: Nftables examples

Arch Linux Wiki: Nftables

Proxied content from gemini://perso.pw/blog/articles/nftables.gmi (external content)

Gemini request details:

Original URL
gemini://perso.pw/blog/articles/nftables.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.