iptables
networkingLinux
The iptables command is one of the most frequently used commands in Linux/Unix-like operating systems. iptables Administration tool for IPv4 packet filtering and NAT
Quick Reference
Command Name:
iptables
Category:
networking
Platform:
Linux
Basic Usage:
iptables [options] [arguments]
Common Use Cases
Syntax
iptables [-t table] command [chain] [rule-specification] [options]
Options
Option | Description |
---|---|
-t, --table table |
The table to operate on (filter, nat, mangle, raw, security) |
-A, --append chain |
Append rule to the end of the specified chain |
-D, --delete chain rule |
Delete rule from chain |
-I, --insert chain [rule] |
Insert rule at position in chain (default 1) |
-R, --replace chain rule |
Replace rule in chain |
-L, --list [chain] |
List all rules in chain (or all chains) |
-F, --flush [chain] |
Delete all rules in chain (or all chains) |
-Z, --zero [chain] |
Zero packet and byte counters in chain |
-N, --new-chain chain |
Create a new user-defined chain |
-X, --delete-chain [chain] |
Delete a user-defined chain |
-P, --policy chain target |
Set policy for chain (ACCEPT or DROP) |
-E, --rename-chain old new |
Rename a user-defined chain |
-p, --protocol protocol |
Protocol of the rule (tcp, udp, icmp, all) |
-s, --source address |
Source address (network name, IP address, network/mask) |
-d, --destination address |
Destination address |
-i, --in-interface name |
Network interface name the packet was received on |
-o, --out-interface name |
Network interface name the packet will go out on |
-j, --jump target |
Target of the rule (ACCEPT, DROP, REJECT, etc.) |
-m, --match match |
Extended match (state, conntrack, limit, etc.) |
-v, --verbose |
Verbose output |
-n, --numeric |
Numeric output of addresses and ports |
--line-numbers |
Show line numbers when listing rules |
Examples
How to Use These Examples
The examples below show common ways to use the iptables
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
iptables -L