nftables is the replacement for the deprecated iptables.
Quick Overview
Nftables uses the following objects:
- A
tablecontains a set ofchainsnft add table <table_address_family> <table_name>
- A
chaincontains a set ofrulesand has a default policynft add chain ip my-table my-chain { type filter hook input priority -150 \; policy drop \; }
- A
ruledetermines if a package is allowed or blocked- Add rule at the end →
nft add rule <table_address_family> <table_name> <chain_name> <rule> - Add rule in the beginning →
nft add insert <table_address_family> <table_name> <chain_name> <rule>
- Add rule at the end →
You can list all the rules via the nft list ruleset command.
| Type | Address families | Hooks | Description |
|---|---|---|---|
filter | all | all | Standard chain type |
nat | ip, ip6, inet | prerouting, input, output, postrouting | Chains of this type perform native address translation based on connection tracking entries. Only the first packet traverses this chain type. |
route | ip, ip6 | output | Accepted packets that traverse this chain type cause a new route lookup if relevant parts of the IP header have changed. |
nft add rule inet nftables_svc INPUT tcp dport 22 accept
nft add rule inet nftables_svc INPUT tcp dport 443 accept
nft add rule inet nftables_svc INPUT reject with icmpx type port-unreachable