From ae273d1149742d617351b9ddbf131226650cc636 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 12 Aug 2025 20:10:34 +0330 Subject: [PATCH] iptable doc --- Security & Networking/Iptables/iptables.md | 284 ++++++++++++++++++--- Security & Networking/Iptables/temp.md | 114 +++++++++ 2 files changed, 359 insertions(+), 39 deletions(-) create mode 100644 Security & Networking/Iptables/temp.md diff --git a/Security & Networking/Iptables/iptables.md b/Security & Networking/Iptables/iptables.md index ef38fae..6f5185a 100755 --- a/Security & Networking/Iptables/iptables.md +++ b/Security & Networking/Iptables/iptables.md @@ -1,52 +1,258 @@ -## First Whitelist Port and Block Ports at the End +# πŸ›‘οΈ Iptables & Netfilter Guide +## 🌐 Overview -```bash -iptables -A/-I/-D INPUT/OUTPUT/FORWARD -i/-o interface -s/-d address -p tcp/udp/icmp --sport/--dport 80 -j ACCEPT/REJECT/DROP/LOG/MASQUARATE +**iptables** works with **Netfilter** to manage and control network traffic on Linux systems. + +--- + +## πŸ”— Connection Types + +1. **NEW** – A new connection being initiated +2. **ESTABLISHED** – An existing, ongoing connection +3. **RELATED** – A new connection related to an existing one + +--- + +## 🧰 iptables-persistent + +Install iptables and save the rules to a file for persistence across reboots. + +--- + +## πŸ“‚ Default Path + +```plaintext +/etc/iptables ``` -- `-A`: Append -- `-I`: Insert -- `-D`: Delete -- `-i`: Input interface -- `-o`: Output interface -- `-s`: Source -- `-d`: Destination -- `-p`: Protocol -- `--sport`: Source port -- `--dport`: Destination port -- `-j`: Action - - `ACCEPT`: Accept the packet - - `REJECT`: Reject the packet with an appropriate ICMP message - - `DROP`: Silently discard the packet - - `LOG`: Log the packet - - `MASQUERADE`: Source NAT +--- -### Examples: - -- `iptables -nvL`: Print Iptables Rules -- `iptables -P INPUT DROP`: Drop All Incoming Packets -- `iptables -P OUTPUT DROP`: Drop All Outgoing Packets -- `iptables -A INPUT -p tcp --dport 22 -j ACCEPT`: Accept Incoming Traffic to Port 22 with TCP Protocol -- `iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT`: Accept Outgoing Traffic from Port 22 with TCP Protocol -- `iptables -A INPUT -p tcp -s 192.168.1.100 -j DROP`: Drop All Packets Incoming With TCP Protocol From 192.168.1.100 -- `iptables -A INPUT -p tcp --dport 443 -j ACCEPT`: Accept Incoming Traffic to Port 443 (HTTPS) with TCP Protocol -- `iptables -A INPUT -p tcp -m multiport --dport 22,443,80,3306 -j ACCEPT`: Accept Incoming Traffic to Multiple Ports: 22 (SSH), 80 (HTTP), 3306 (Database), 443 (HTTPS) with TCP Protocol -- `iptables -A INPUT -p tcp -m multiport --dport 22,443,80,3306 -d 192.168.10.0/24 -j ACCEPT`: Accept Incoming Traffic to Multiple Ports: 22 (SSH), 80 (HTTP), 3306 (Database), 443 (HTTPS) with TCP Protocol to Destination 192.168.10.0 -- `iptables -A INPUT -p tcp --dport 80 -m limit --limit 100/minute --limit-burst 200 -j ACCEPT`: Allow incoming TCP traffic on port 80 with rate limiting -- `iptables -t NAT -A PREROUTING -i ens33 -p tcp --dport 80 -j REDIRECT --to-port 443`: Redirect traffic from port 80 to port 443 using NAT - -### Saving rules for permanent: - -To save the rules for permanent usage, you can install the `iptables-persistent` package: +## βš™οΈ Command Format ```bash -apt install iptables-persistent +iptables -t