Network

The iptables command

Linux's low-level firewall: chains of rules that filter network traffic.

Syntax

sudo iptables [-L | -A CADENA REGLA | -F]

Most useful options

-LLists the current rules
-AAppends a rule to a chain
-FFlushes all rules
-PSets the default policy

Copy-ready examples

$ sudo iptables -LSee the rules
$ sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTAllow SSH

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Changes with iptables are lost on reboot unless you save them.

Related commands

FAQ

What is a chain?

A list of rules; INPUT is incoming traffic, OUTPUT outgoing.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course