🛡️ Beginner’s Guide to Linux Firewalls: iptables & UFW
Whether you’re running a VPS, a dev box, or a personal server, setting up a firewall is essential. In this guide, we’ll show you how to secure your Linux machine using iptables and UFW, along with some simple but powerful default rules to block bad traffic while keeping your services online.

🧙♂️ Option 1: UFW (Uncomplicated Firewall – beginner-friendly)
✅ Quick Setup (Good Defaults)
# Install UFW (usually pre-installed on Ubuntu)
sudo apt install ufw
# Set default policy: deny all incoming, allow all outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Allow SSH so we don't lock ourselves out
sudo ufw allow ssh
# Allow web traffic
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Enable UFW
sudo ufw enable
# Check status
sudo ufw status verbose
🔥 Option 2: iptables (for advanced users)
iptables is the built-in firewall tool in Linux. It’s powerful, but less user-friendly than UFW. Here’s how to set up safe, common defaults: