Linux Terminal Command: iptables

The iptables command is an essential tool in Network Utilities. In this tutorial, we will explore what iptables does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The iptables command modifies the Linux kernel firewall rule tables, filtering and routing IP packets.


Common Options & Syntax

iptables [options] [arguments]

Here are the most common flags used with iptables:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
sudo iptables -L -n -v

What it does: Lists all active firewall rules in verbose numeric format.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
sudo iptables -A INPUT -p tcp --dport 22 -s 192.168.1.100 -j ACCEPT && sudo iptables -A INPUT -p tcp --dport 22 -j DROP

What it does: Allows SSH access only from IP 192.168.1.100, blocking all other SSH connections.


⚙️ Warning & Common Pitfalls

[!WARNING] iptables rules are processed sequentially. If you place a DROP rule before an ACCEPT rule, packets will be blocked immediately.


Here are some related posts on cli_tty1 you might want to check out: