Iptables Essentials: Common Firewall Rules and Commands

Iptables Essentials: Common Firewall Rules and Commands


Iptables is a powerful firewall tool that comes pre-installed on most Linux distributions. It provides a way to control network traffic by setting rules for incoming and outgoing packets. In this article, we will cover some of the most common firewall rules and commands that you can use with iptables.

Basic Firewall Rules

Before we dive into the commands, let’s first take a look at some basic firewall rules that you should be aware of:

1. Allow all outgoing traffic:


2. Block all incoming traffic:

iptables -P INPUT DROP

3. Allow established connections:

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

4. Allow SSH access:

iptables -A INPUT -p tcp --dport ssh -j ACCEPT

5. Allow HTTP/HTTPS traffic:

iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport https -j ACCEPT

Common Iptables Commands

Now that we know some basic rules, let’s take a look at some of the most common iptables commands:

1. View current rules:

iptables -L

2. Flush all rules:

iptables -F

3. Save current rules:

iptables-save > /etc/sysconfig/iptables

4. Restore saved rules:

iptables-restore < /etc/sysconfig/iptables

5. Block an IP address:

iptables -A INPUT -s <IP_ADDRESS> -j DROP

6. Allow an IP address:

iptables -A INPUT -s <IP_ADDRESS> -j ACCEPT


Iptables is a powerful tool that can help you secure your network by controlling incoming and outgoing traffic. By using the basic rules and commands outlined in this article, you can get started with iptables and begin protecting your system. Remember to always test your rules before implementing them in a production environment, and to keep your firewall rules up to date as new threats emerge. Sprawdź naszą ofertę hostingową, która obejmuje szybkie serwery, niezawodność i najlepszą obsługę klienta