Iptables Firewall Quick Start Guide

25-01-2024 02:35:03

Iptables is a tool used to configure the Linux kernel firewall. This quick start guide lists some commonly used iptables commands, enabling system administrators to quickly master the usage of iptables.

Listing all active rules:

iptables -L -v

Disabling and flushing iptables:

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F

Blocking all traffic:

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

Allowing SSH, HTTP, and HTTPS, while blocking other traffic:

iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -j DROP

For more information, refer to the official CentOS and Ubuntu documentation.