iptables Command Examples

Configure tables, chains and rules of the Linux kernel IPv4 firewall. Use ip6tables to set rules for IPv6 traffic. See also: iptables-save, iptables-restore. More information: https://manned.org/iptables.

sudo iptables --verbose --numeric --list --line-numbers

sudo iptables --policy {{chain}} {{rule}}

sudo iptables --append {{chain}} --source {{ip}} --jump {{rule}}

sudo iptables --append {{chain}} --source {{ip}} --protocol {{tcp|udp|icmp|...}} --dport {{port}} --jump {{rule}}

sudo iptables --table {{nat}} --append {{POSTROUTING}} --source {{192.168.0.0/24}} --jump {{MASQUERADE}}

sudo iptables --delete {{chain}} {{rule_line_number}}