Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Nftables Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-nftables-knowledge-patch)
---
name: nftables-knowledge-patch
description: nftables
version: "1.1.6"
license: MIT
metadata:
author: Nevaberry
---
# nftables Knowledge Patch
Load this skill when writing or restoring nftables rulesets, managing sets and
stateful objects, using JSON or libnftables, inspecting hooks, or building nftables.
The references provide syntax, examples, validation rules, and behavior changes
organized by task, with version-specific details beside the relevant guidance.
## Reference index
| Reference | Topics |
| --- | --- |
| [Build, packaging, and releases](references/build-packaging-and-releases.md) | Removed protocol support, dependencies, Python bindings, systemd, build checks, archives, signatures, checksums |
| [CLI, files, and lifecycle](references/cli-files-and-lifecycle.md) | Includes, variables, table ownership, anonymous chains, rule placement, listing, resets, optimizer |
| [Expressions and protocols](references/expressions-and-protocols.md) | Bitwise operations, protocol guards, raw payload, TCP options, SCTP, cgroups, tunnels, overlay headers |
| [Hooks, NAT, and packet path](references/hooks-nat-and-packet-path.md) | FIB, NAT maps and prefixes, flowtables, device wildcards, priorities, forwarding, IPsec, hook order |
| [JSON, monitoring, and embedding](references/json-monitoring-and-embedding.md) | JSON shapes and validation, trace data, listings, netlink behavior, libnftables, debugging |
| [Sets, maps, and state](references/sets-maps-and-state.md) | Type checks, intervals, timeouts, capacity, queue and object maps, meters, conntrack, quotas, limits |
## Compatibility changes first
Remove DECnet rules from rulesets loaded with 1.0.6.1. Libnftables removed the
`nft_bison_have_extended_errors` symbol in 1.1.7.
Python bindings use setuptools with a PEP 517 build and are installed separately
from the Autotools build. From the source tree, run `python3 -m pip install ./py`.
Static-ruleset systemd unit installation is disabled by default. Enable it at
configure time with `--with-unitdir=/usr/lib/systemd/system`, using the unit
directory for the distribution. Ancillary systemd files are installed only when
the service file is installed.
Libnftables no longer re-adds the default include directory. An application that
clears the search path must explicitly add that directory if it still needs it.
JSON flag shape depends on version: 1.1.4 emits a single flag as a string and
multiple flags as an array for sets, FIB expressions, and SYNPROXY. In 1.1.5,
array-valued fields retain their array shape even with one item, for example
`"flags": ["interval"]`.
For 1.0.6.1, use a meter declaration that creates its own state: that stable-branch
release reverts reuse of an existing metered set.
Rules shown with `xt match`, `xt target`, or `xt watcher` require xtables
compatibility tools for management and restoration. Treat these entries as
placeholders when preparing a native ruleset restore.
## Set and map validation
Use serializable selectors in `typeof`; JSON set and map declarations also
support these selectors. Only stateful statements are accepted in set and map
definitions, including JSON set elements.
Redeclarations under the same name must agree on container kind and declared
types. Element keys are checked against the declared key type, and map values
against the declared value type. Merging declarations must agree on
`flags interval`.
`auto-merge` requires a non-concatenated interval set. In 1.1.2 it skips elements
with a timeout or expiration; in 1.1.3, intervals with different timeouts can
merge again when `auto-merge` is enabled.
`get element` returns the interval containing the lookup key, including its value
for a map. `reset element` also accepts a key inside an interval. Open-interval
lookups are corrected in 1.1.7.
## Packet-path updates and element lifetime
Declare a `size` for sets updated from rules with `add` or `update`. The `dynamic`
and `interval` flags are mutually exclusive. Expired elements can occupy capacity
until garbage collection reclaims them.
`update @recent { ip saddr }` requires timeout support, enabled by a declaration
such as `timeout 1m`. Include `flags dynamic` if the update expression carries
state, such as a per-element rate limit.
```nft
set recent {
type ipv4_addr
flags dynamic,timeout
size 65535
timeout 1m
gc-interval 10s
}
```
Maps accept `gc-interval` to control collection of expired entries. When restoring
timeout-enabled sets or maps, `expires` is the remaining lifetime and `timeout`
is the configured lifetime.
```sh
nft 'add element inet filter blocked { 198.51.100.7 timeout 1h expires 12m }'
```
`create element` requires every supplied key to be new; it fails if any supplied
key already exists. `reset set` and `reset map` reset counters and quotas attached
to all elements of the named container.
## Stateful objects and map values
Maps can return named `ct helper`, `ct timeout`, and `ct expectation` objects.
Object maps accept `typeof` key selectors, such as `typeof tcp dport : ct helper`.
Use `queue` as the value selector in a `typeof` declaration for queue-number maps,
then pass the lookup to the `queue` statement.
Anonymous verdict-map elements can carry stateful statements such as counters;
the optimizer preserves those counters. Set declarations can maintain a quota
for each element.
Connection limits can be named stateful objects. Place `ct state new` before
`ct count` to evaluate the limit only on packets in the new conntrack state.
Declare `protocol`, `dport`, `timeout`, and `size` on a named expectation object.
`l3proto` defaults to the table's family. Assign the object on the control
connection with `ct expectation set`.
## Loading and validating rulesets
`nft -f` accepts regular files and named pipes; `/dev/stdin` bypasses the file-type
check. The ruleset `include` directive requires regular files.
Loading a named file with `nft -f` puts that file's directory first on the include
search path, before directories added with `-I`. A path starting with `./`
resolves from the working directory and bypasses the include search path.
Wildcard includes load in C-locale collation order, skip dotfiles, and succeed
with zero matches. `-D name=value` works only with `-f`.
```sh
nft -c -D uplink=eth0 -f ruleset.nft
nft -c -o -f ruleset.nft
```
The first command validates a ruleset that references `$uplink`; the second
previews optimizer merges. The optimizer skips merges that would create duplicate
keys. When merging NAT rules, it skips statements already using a map or a
ruleset variable.
## Expressions and protocol guards
Compound bitwise assignments combining multiple packet expressions require
Linux 6.13 or newer. The right-hand operand of `^` must be constant. A single
expression can chain at most 16 binary operations; a shift count may exceed the
bit width of its left operand.
```nft
ct mark set ct mark & 0xffff0000 | meta mark & 0xffff
meta mark set meta mark ^ 0x1
```
`@ih,offset,length` reads bits after the transport header. Supply an explicit
transport protocol guard for raw payload matches and the `th dport` shorthand.
A named set matched against `meta l4proto` can satisfy a statement's transport
protocol dependency, including for `tproxy`.
```nft
meta l4proto udp @ih,0,8 0x80 counter
meta l4proto { tcp, udp } th dport { 53, 80 } counter
```
Tunnel templates support VXLAN, ERSPAN, and Geneve. Tunnel source and destination
addresses must be symbolic expressions; the source may be omitted. Specify each
of `ip saddr` and `ip daddr` at most once and use one tunnel section per definition.
For Geneve or VXLAN header expressions, match outer UDP first, typically on
destination port 6081 or 4789, respectively. See the expressions reference for
GRE, encapsulated Ethernet fields, and tunnel object operations.
## Routing, NAT, and hooks
FIB `check` returns `exists` or `missing` and works in matches, map keys, and
expressions assigned by a `set` statement. FIB `oif` and `oifname` results are
available in prerouting, input, and forward. For a `type` result, `. iif` limits
lookup to those hooks; `. oif` limits it to forward, output, and postrouting.
A NAT statement using a map rejects a separately specified NAT protocol operand.
An `inet` NAT rule can infer its address family from the mapping value type.
For a named map returning both an address range and a port range, declare
`interval` on the value side of `typeof`; both range endpoints are included.
Creating a flowtable requires a hook and a priority. Device prefix wildcards
such as `eth*` work in netdev hooks and flowtable device lists. Existing `inet`
ingress base chains can have their device bindings updated in place.
Netdev ingress runs after packet taps and `tc ingress`; netdev egress runs before
`tc egress`. A packet redirected from ingress to another device's egress reaches
netfilter egress only if it already passed through netfilter ingress.
With XFRM interfaces, place outbound IPsec policy matches in postrouting: the
packet receives its IPsec metadata after the output hook in this setup.
## Rule lifecycle and observation
`add rule` places a rule after the specified location; `insert rule` places it
before. Native zero-based indices are resolved to handles before submission;
concurrent edits can change the target's position or delete it and cause failure.
JSON rule commands can use `handle` for the insertion point.
`destroy` permits an absent rule or object. An existing chain must still be empty
and unreferenced for `destroy chain`. Reset individual stateful objects by name.
`reset rules [family] [table [chain]]` resets rule-local state in the selected scope.
A reset with `-c` or `--check` is a dry run in 1.1.7.
`nft monitor trace` can emit connection direction, state, ID, and reported status
flags on a `conntrack:` line. Use the conntrack ID to correlate across hooks.
`nft list hooks ip` includes implicit kernel hooks in processing order and
requires `CONFIG_NETFILTER_NETLINK_HOOK`, built in or available as `nfnetlink_hook`.
## Building and checking distributions
Use `make check` for the test suite. `make distcheck` works again, and build
commands honor `CFLAGS` overrides supplied to `make`. Set `SOURCE_DATE_EPOCH`
when running `./configure` to supply the build timestamp; use
`./configure --enable-profiling` for profiling builds.
Use the signature key linked beside the release's `.sig` file. The build reference
contains library requirements, archive suffixes, signature keys, and the published
checksum lines and verification command.