Console9

iptables and nftables commands reference

Complete reference for iptables and nftables commands, chain targets, match extensions, and rule syntax.

iptables and nftables commands reference

Complete reference for iptables and nftables commands, chain targets, and common rule patterns.

iptables Command Flags

FlagDescriptionExample
-A CHAINAppend a rule to the end of a chain.iptables -A INPUT -p tcp --dport 22 -j ACCEPT
-I CHAIN [N]Insert a rule at position N (default: 1, top).iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
-D CHAIN RULEDelete a specific rule from a chain.iptables -D INPUT -p tcp --dport 8080 -j ACCEPT
-L [CHAIN]List rules in a chain (or all chains).iptables -L INPUT -n -v
-F [CHAIN]Flush (delete) all rules in a chain.iptables -F INPUT
-P CHAIN TARGETSet the default policy for a chain.iptables -P INPUT DROP
-t TABLESpecify the table (filter, nat, mangle, raw).iptables -t nat -L
-p PROTOCOLMatch protocol (tcp, udp, icmp).-p tcp
--dport PORTMatch destination port.--dport 443
--sport PORTMatch source port.--sport 1024:65535
-s IPMatch source IP address or CIDR.-s 203.0.113.0/24
-d IPMatch destination IP address or CIDR.-d 10.0.0.1
-i IFACEMatch input interface.-i eth0
-o IFACEMatch output interface.-o wg0
-m state --stateMatch connection state (NEW, ESTABLISHED, RELATED).-m state --state ESTABLISHED,RELATED
-j TARGETJump to target (ACCEPT, DROP, REJECT, DNAT, SNAT, MASQUERADE, LOG).-j DROP

nftables Common Commands

CommandDescriptionExample
nft list rulesetDisplay all tables, chains, and rules.sudo nft list ruleset
nft add tableCreate a new table.nft add table ip filter
nft add chainCreate a chain with a hook and priority.nft add chain ip filter input { type filter hook input priority 0; }
nft add ruleAdd a rule to a chain.nft add rule ip filter input tcp dport 22 accept
nft delete ruleDelete a specific rule by handle.nft delete rule ip filter input handle 5
nft flush rulesetRemove all rules, chains, and tables.nft flush ruleset
nft list ruleset -aShow rules with handle numbers for deletion.sudo nft list ruleset -a