Skip to content

How to Create nftables Chains

DodaTech Updated 2026-06-24 2 min read

Chains in nftables are either base chains (attached to kernel hooks) or regular chains (called from other chains). Proper hook and priority configuration is essential. This guide walks through the specific troubleshooting steps to diagnose and resolve chain creation 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 add chain inet filter mychain (no hook specified)

Wrong: Creating a chain without specifying hook type

nft add chain inet filter input { type filter hook input priority 0; policy drop; }

Right: Base chain with hook, priority, and policy

Output

Chain input created\n  Type: filter\n  Hook: input\n  Priority: 0\n  Policy: drop

Prevention

To avoid future issues, follow these best practices:

  • Base chains require a hook (input, output, forward, prerouting, postrouting)
  • Regular chains have no hook and are called by jump/goto from other chains
  • Priority determines evaluation order for chains on the same hook
  • Set policy to drop or accept for base chains
  • Use a chain priority of -150 for raw table equivalent, 0 for filter, 100 for NAT

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 chain create

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

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

What is the difference between base chains and regular chains?|||Base chains are attached to a kernel hook and process packets directly. Regular chains are called from other chains via jump or goto.
How does priority work in nftables chains? Lower priority numbers run first. The filter chain typically uses priority 0. Raw table chains use -150. NAT chains use 100.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro