Search Our Database
How to Safely Migrate from iptables-legacy to nftables
Introduction
Linux firewall management has evolved significantly over the years, with iptables being the traditional standard for configuring packet filtering rules. However, with the introduction of the nftables framework in Linux kernel 3.13 and beyond, a more modern and efficient alternative is now available. As of recent Linux distributions—such as Debian 10+, Ubuntu 20.04+, and CentOS/RHEL 8+—nftables is often the default firewall backend.
This guide explains how to safely migrate from iptables-legacy to nftables, covering key compatibility concerns, toolchains, and best practices for preserving firewall rules during the transition. It is particularly useful for system administrators managing production servers, cloud infrastructure, or Linux-based firewalls.
The migration process must be handled carefully to avoid disruptions in traffic filtering, VPN connections, NAT configurations, or service availability. Both iptables and nftables operate at the kernel level, and misconfiguration during the switch can inadvertently disable critical network policies.
By the end of this guide, readers will be able to:
- Identify the active firewall backend.
- Convert iptables rules to nftables syntax.
- Switch to the iptables-nft backend safely.
- Enable and manage nftables services and rules.
Prerequisites
- Linux distribution with kernel version 3.13 or newer.
- Root or sudo privileges.
- iptables, iptables-nft, and nftables installed.
- Backups of iptables rules using iptables-save and ip6tables-save.
Step-by-step Guide
Step 1: Check the Current iptables Backend
Run the following commands to see which version of iptables is currently in use:
sudo update-alternatives --display iptables
Output will indicate whether the system is using iptables-legacy or iptables-nft.
Step 2: Backup Existing iptables Rules
Before making any changes, export current rules:
sudo iptables-save > ~/iptables-backup.rules sudo ip6tables-save > ~/ip6tables-backup.rules
Keep these files secure in case rollback is necessary.
Step 3: Install nftables if Not Already Installed
For Debian-based systems:
sudo apt update sudo apt install nftables
For RHEL-based systems: