InfraLab
NFTABLES34 cmd

nftables チート集

iptables 後継の nftables で ruleset、table/chain、filter rule、NAT、set/map、ログ、保存復元、iptables-translate を扱う Linux ファイアウォール運用チート集。

更新日
2026-05-29
参照範囲
公式ドキュメント / man page / 主要ベンダーCLI
対象実装
主要 Linux / BSD / ネットワーク機器 CLI の一般的な実装
免責
OS とバージョン差分は実環境で確認してください。

このチートシートの使いどころ

nftables チートシートは、iptables 後継の nft コマンドで ruleset、table、chain、rule、set、map、NAT、ログ、保存復元を扱うための運用メモです。対象は nftables を標準利用する現行 Linux です。iptables からの移行、恒久設定前の検証、通信許可/拒否の切り分けで、まず現在の ruleset を読み、最小単位で変更する用途に向きます。

34 / 34

nft list ruleset

nftables で nft list ruleset を実務運用で使う

Example
$ sudo nft list ruleset
nft -a list ruleset

nftables で nft -a list ruleset を実務運用で使う

Example
$ sudo nft -a list ruleset
nft flush ruleset

nftables で nft flush ruleset を実務運用で使う

Example
$ sudo nft flush ruleset
nft monitor trace

nftables で nft monitor trace を実務運用で使う

Example
$ sudo nft monitor trace
nft add table inet filter

nftables で nft add table inet filter を実務運用で使う

Example
$ sudo nft add table inet filter
nft add chain inet filter input

nftables で nft add chain inet filter input を実務運用で使う

Example
$ sudo nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }
nft add chain inet filter forward

nftables で nft add chain inet filter forward を実務運用で使う

Example
$ sudo nft add chain inet filter forward { type filter hook forward priority 0 \; policy drop \; }
nft add chain inet filter output

nftables で nft add chain inet filter output を実務運用で使う

Example
$ sudo nft add chain inet filter output { type filter hook output priority 0 \; policy accept \; }
nft delete table inet filter

nftables で nft delete table inet filter を実務運用で使う

Example
$ sudo nft delete table inet filter
nft add rule ct state

nftables で nft add rule ct state を実務運用で使う

Example
$ sudo nft add rule inet filter input ct state established,related accept
nft add rule iif lo

nftables で nft add rule iif lo を実務運用で使う

Example
$ sudo nft add rule inet filter input iif lo accept
nft add rule tcp dport

nftables で nft add rule tcp dport を実務運用で使う

Example
$ sudo nft add rule inet filter input tcp dport { 22, 443 } accept
nft add rule ip saddr

nftables で nft add rule ip saddr を実務運用で使う

Example
$ sudo nft add rule inet filter input ip saddr 10.0.0.0/8 accept
nft add rule log drop

nftables で nft add rule log drop を実務運用で使う

Example
$ sudo nft add rule inet filter input log prefix "nft-drop " drop
nft insert rule

nftables で nft insert rule を実務運用で使う

Example
$ sudo nft insert rule inet filter input position 0 ip saddr 192.0.2.10 drop
nft delete rule handle

nftables で nft delete rule handle を実務運用で使う

Example
$ sudo nft delete rule inet filter input handle 12
nft add table ip nat

nftables で nft add table ip nat を実務運用で使う

Example
$ sudo nft add table ip nat
nft add chain prerouting nat

nftables で nft add chain prerouting nat を実務運用で使う

Example
$ sudo nft add chain ip nat prerouting { type nat hook prerouting priority -100 \; }
nft add chain postrouting nat

nftables で nft add chain postrouting nat を実務運用で使う

Example
$ sudo nft add chain ip nat postrouting { type nat hook postrouting priority 100 \; }
nft masquerade

nftables で nft masquerade を実務運用で使う

Example
$ sudo nft add rule ip nat postrouting oif eth0 masquerade
nft dnat

nftables で nft dnat を実務運用で使う

Example
$ sudo nft add rule ip nat prerouting tcp dport 443 dnat to 10.0.10.10:443
nft snat

nftables で nft snat を実務運用で使う

Example
$ sudo nft add rule ip nat postrouting ip saddr 10.0.0.0/24 snat to 203.0.113.10
nft add set

nftables で nft add set を実務運用で使う

Example
$ sudo nft add set inet filter blocklist { type ipv4_addr \; flags interval \; }
nft add element

nftables で nft add element を実務運用で使う

Example
$ sudo nft add element inet filter blocklist { 192.0.2.10, 198.51.100.0/24 }
nft delete element

nftables で nft delete element を実務運用で使う

Example
$ sudo nft delete element inet filter blocklist { 192.0.2.10 }
nft add rule @set

nftables で nft add rule @set を実務運用で使う

Example
$ sudo nft add rule inet filter input ip saddr @blocklist drop
nft add map

nftables で nft add map を実務運用で使う

Example
$ sudo nft add map inet filter portmap { type inet_service : verdict \; }
nft add rule vmap

nftables で nft add rule vmap を実務運用で使う

Example
$ sudo nft add rule inet filter input tcp dport vmap @portmap
nft list set

nftables で nft list set を実務運用で使う

Example
$ sudo nft list set inet filter blocklist
nft list ruleset > file

nftables で nft list ruleset > file を実務運用で使う

Example
$ sudo nft list ruleset > /etc/nftables.conf
nft -f

nftables で nft -f を実務運用で使う

Example
$ sudo nft -f /etc/nftables.conf
systemctl enable nftables

nftables で systemctl enable nftables を実務運用で使う

Example
$ sudo systemctl enable --now nftables
iptables-translate

nftables で iptables-translate を実務運用で使う

Example
$ iptables-translate -A INPUT -p tcp --dport 22 -j ACCEPT
iptables-save-translate

nftables で iptables-save-translate を実務運用で使う

Example
$ iptables-save | iptables-restore-translate -f -
対応ツール
Related