iptables
NetworkAdvanced In real LinuxConfigure Linux firewall rules
Name: iptables: IP (packet filter) tables
This command needs a real Linux system; you can practise it in real Linux mode.
Description
iptables configures the Linux kernel's packet filtering (firewall) rules, organised in tables (filter, nat …) and chains (INPUT, OUTPUT, FORWARD …). Packets are matched against rules in order to be accepted, dropped or translated.
Rules are lost on reboot unless saved. Newer systems use nftables underneath, and ufw or firewalld are easier for beginners.
Syntax
iptables [OPTION]... CHAIN RULECommon options
| -L | List rules |
| -n | With -L: numeric addresses and ports, no lookups (faster) |
| -v | More detail (packet and byte counts, interfaces) |
| --line-numbers | Show rule numbers (for deleting or inserting) |
| -A | Append a rule |
| -I | Insert a rule at the top of a chain (or at a position) |
| -D | Delete a rule |
| -F | Delete every rule in a chain |
| -P | Set a chain’s policy, e.g. -P INPUT DROP |
| -p / --dport / -j | Protocol / port / target (ACCEPT, DROP) |
| -s / --source ADDRESS | Source address, e.g. -s 192.168.1.0/24 |
| -i IFACE | The incoming interface, e.g. -i eth0 |
| -t TABLE | The table, e.g. -t nat (filter by default) |