cmdxray / commands / iptables

What does iptables do?

administer the Linux kernel IPv4 packet-filter rules (netfilter firewall).

▸ Explain your own iptables command →

iptables examples, explained

$ iptables -A INPUT -p tcp --dport 22 -j ACCEPT

  • iptablesadminister the Linux kernel IPv4 packet-filter rules (netfilter firewall)
  • -Aappend a rule to the end of the given chain
  • INPUTvalue for -A
  • -pmatch a protocol (tcp, udp, icmp, ...)
  • tcpvalue for -p
  • --dportmatch the destination port
  • 22value for --dport
  • -jjump to a target (ACCEPT, DROP, REJECT, ...) on a match
  • ACCEPTvalue for -j

$ iptables -L -n -v

  • iptablesadminister the Linux kernel IPv4 packet-filter rules (netfilter firewall)
  • -Llist all rules in a chain
  • -nnumeric output — don't resolve host names or ports
  • -vverbose output

$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

  • iptablesadminister the Linux kernel IPv4 packet-filter rules (netfilter firewall)
  • -toperate on the given table (filter, nat, mangle, raw)
  • natvalue for -t
  • -Aappend a rule to the end of the given chain
  • POSTROUTINGvalue for -A
  • -omatch the output network interface
  • eth0value for -o
  • -jjump to a target (ACCEPT, DROP, REJECT, ...) on a match
  • MASQUERADEvalue for -j

iptables flags & options

-Aappend a rule to the end of the given chain
-Iinsert a rule at a position in a chain (default: the top)
-Ddelete a matching rule from a chain
-Llist all rules in a chain
-Fflush — delete every rule in a chain
-Ncreate a new user-defined chain
-Xdelete an empty user-defined chain
-Pset the default policy (ACCEPT/DROP) for a built-in chain
-pmatch a protocol (tcp, udp, icmp, ...)
-smatch a source address or subnet
-dmatch a destination address or subnet
-jjump to a target (ACCEPT, DROP, REJECT, ...) on a match
-imatch the input network interface
-omatch the output network interface
-mload an extension match module (e.g. state, conntrack)
-nnumeric output — don't resolve host names or ports
-vverbose output
-toperate on the given table (filter, nat, mangle, raw)
--dportmatch the destination port
--sportmatch the source port
--statematch connection state (NEW, ESTABLISHED, RELATED)
--line-numbersshow rule line numbers when listing

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.