iptables
10 commands
10 shown
List rules with line numbers
Show INPUT chain rules with packet/byte counters
iptables -L INPUT --line-numbers -n -v
Allow incoming port
Append a rule to accept inbound HTTPS traffic
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
Block IP address
Insert DROP rule at position 1 for a specific source IP
iptables -I INPUT 1 -s 203.0.113.5 -j DROP
NAT: masquerade outbound
Enable IP masquerading for outbound traffic (router/NAT)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Save and restore rules
Persist rules across reboots
iptables-save > /etc/iptables/rules.v4
iptables-restore < /etc/iptables/rules.v4
Delete a rule by number
Remove rule number 3 from the INPUT chain
iptables -D INPUT 3
Rate-limit connections
Allow max 3 new SSH connections per minute
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/min --limit-burst 5 -j ACCEPT
nftables: list all rules
Show complete nftables configuration
nft list ruleset
nftables: add accept rule
Accept inbound TCP traffic on port 8080 in nftables
nft add rule inet filter input tcp dport 8080 accept
nftables: flush all rules
Delete all nftables rules (caution: drops all firewall rules)
nft flush ruleset
no commands match