Skip to content

How to Delete Rules from nftables

DodaTech Updated 2026-06-24 2 min read

Deleting individual rules by handle preserves other rules in the chain. This avoids the disruption of flushing and recreating. This guide walks through the specific troubleshooting steps to diagnose and resolve rule deletion issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

nft flush chain inet filter input (removes all rules)

Wrong: Flushing the whole chain to remove one rule

nft -a list chain inet filter input && nft delete rule inet filter input handle 3

Right: Deleting a single rule by its handle

Output

Rule with handle 3 deleted\nChain input unchanged except for removed rule

Prevention

To avoid future issues, follow these best practices:

  • Use nft -a to display rule handles before deletion
  • Delete individual rules by handle to avoid affecting other rules
  • Replace rules with nft replace rule for in-place updates
  • Use handle numbers from the live ruleset, not from config files
  • Script handle-based deletions carefully as handles change when rules are added/removed

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with delete rule

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world NFTABLES code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How do I find the handle number of an nftables rule?|||Run nft -a list chain inet filter input. The handle number appears in parentheses after each rule.
What happens to rule handles after deletion? Remaining rule handles stay the same. New rules receive the next available handle number.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro