Skip to content

Linux Firewall

Here's a combined explanation of iptables and UFW, including installation, usage, and key concepts.


Introduction to iptables and UFW

iptables

iptables is a command-line utility that configures the Linux netfilter firewall. It allows filtering, NAT (Network Address Translation), and packet manipulation at the kernel level.

UFW (Uncomplicated Firewall)

ufw is a user-friendly front-end for iptables, designed to simplify firewall management.


Installation (if missing)

If iptables or ufw are not found, install them:

sudo apt update
sudo apt install iptables ufw -y

1️⃣ Using iptables

Check Existing Rules

sudo iptables -L -v -n

Allow SSH (Port 22)

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Block an IP Address

sudo iptables -A INPUT -s 192.168.1.100 -j DROP

Save iptables Rules

To make changes persistent:

sudo iptables-save | sudo tee /etc/iptables/rules.v4

2️⃣ Using UFW

Enable UFW

sudo ufw enable

Check Firewall Status

sudo ufw status verbose

Allow SSH

sudo ufw allow 22/tcp

Deny Specific IP

sudo ufw deny from 192.168.1.100

Disable UFW

sudo ufw disable

3️⃣ Open SSH Port on Parrot OS

Enable SSH service:

sudo systemctl enable ssh
sudo systemctl start ssh

Allow SSH through UFW:

sudo ufw allow 22/tcp

Or using iptables:

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

4️⃣ SCP Command to Copy Files Using IP

Copy File to VM

scp /path/to/file user@remote-ip:/path/to/destination

Example:

scp myfile.txt yuva@192.168.1.10:/home/yuva/

Copy File from VM to Local

scp user@remote-ip:/path/to/file /local/destination

Example:

scp yuva@192.168.1.10:/home/yuva/myfile.txt ~/Downloads/

5️⃣ Closing SSH

Stop SSH Service

sudo systemctl stop ssh

Disable SSH on Boot

sudo systemctl disable ssh

Block SSH with UFW

sudo ufw deny 22/tcp

Block SSH with iptables

sudo iptables -A INPUT -p tcp --dport 22 -j DROP

Now you have a complete guide to managing firewalls and SSH on your Parrot VM. Let me know if you need more details! 🚀