Course contentsShow
← Security
Lesson 444 of 3,05210. Network Security - Firewalls and SegmentationFree lesson

nftables Rule Syntax and Families

Writing nftables rules across ip, ip6, inet, arp, and bridge families with modern matching expressions.

nftables Rule Syntax and Families

You'll learn how to write nftables rules across different protocol families and understand modern matching expressions.

The Core Concept

Unlike iptables (which required separate commands for IPv4, IPv6, and other protocols), nftables introduces families that let you organize rules by network layer protocol in a unified framework. Each family operates on a specific protocol type, and you write rules using a more readable, consistent syntax across all of them.

The Five Main Families

  • ip – IPv4 only (like old iptables)
  • ip6 – IPv6 only (like old ip6tables)
  • inet – Both IPv4 and IPv6 together (modern dual-stack)
  • arp – ARP protocol (like old arptables)
  • bridge – Bridged traffic (like old ebtables)

Think of families as different "languages" your firewall speaks. The inet family is like being bilingual—it understands both IPv4 and IPv6 in one ruleset.

Modern Rule Syntax

nftables uses a cleaner syntax:

nft add rule inet filter input ip saddr 192.168.1.0/24 tcp dport 22 accept

This rule uses the inet family (dual-stack), matches IPv4 source addresses from a subnet, checks TCP destination port 22, and accepts the packet.

Key improvements:

  • Protocol-specific matching is explicit: ip saddr (IPv4) vs ip6 saddr (IPv6)
  • More natural language: tcp dport 22 instead of --dport 22
  • You can use inet for most rules and let nftables handle both IP versions

Choosing the Right Family

Use inet for most firewall rules today—it's simpler and handles modern dual-stack networks. Use ip or ip6 only when you need protocol-specific features. Reserve arp and bridge for specialized layer-2 security.

Key Takeaway: nftables organizes rules by protocol family (ip, ip6, inet, arp, bridge), with inet being the modern choice for writing single rules that handle both IPv4 and IPv6 traffic using cleaner, more consistent syntax.