🔥 How to Set Up a Firewall on Linux with UFW (Ultimate Security Guide)

Vastrox

Administrator
Staff member
Owner
Joined
May 29, 2025
Messages
30
Reaction score
0
Points
6

🔥 How to Set Up a Firewall on Linux with UFW (Ultimate Security Guide)​


Setting up a firewall is one of the most important steps in securing your Linux server. Whether you’re hosting websites, APIs, or game servers, having the right firewall configuration helps protect your system from unauthorized access and attacks.


In this guide, we’ll walk you through how to set up and manage UFW (Uncomplicated Firewall) — a powerful yet easy-to-use tool built into most modern Linux distributions.


🔐 Powered by Vastrox.com — the cloud platform built for speed, security, and simple server management.



✅ What Is UFW?​


UFW stands for Uncomplicated Firewall, and it's a frontend for iptables designed to make configuring a Linux firewall easier.


With just a few commands, you can:


  • Allow or block traffic to specific ports
  • Set default deny rules
  • Allow only certain IP addresses
  • Secure your server in minutes

UFW comes pre-installed on most Ubuntu and Debian-based distributions, and it can be installed on others like CentOS and AlmaLinux.




🧰 What You’ll Need​


  • A Linux server (Ubuntu, Debian, AlmaLinux, etc.)
  • Root or sudo access
  • OpenSSH access (for remote management)

🔎 Tip: If you're using Vastrox to deploy your server, UFW comes pre-installed and can be enabled instantly with custom port rules.



🧩 Step 1: Install and Enable UFW​


On Ubuntu/Debian:​


UFW is usually pre-installed. If not:


sudo apt install ufw

On CentOS/RHEL/AlmaLinux:​


First, install UFW:


sudo yum install epel-release
sudo yum install ufw

Then enable the UFW service:


sudo systemctl enable ufw
sudo systemctl start ufw



🛡️ Step 2: Set Default Rules​


First, set the default behavior:


sudo ufw default deny incoming
sudo ufw default allow outgoing

This blocks all incoming connections except those you explicitly allow, while letting your server send data out freely.




🔓 Step 3: Allow SSH Access​


Before enabling UFW, allow SSH access so you don’t get locked out:


sudo ufw allow ssh

Or if your SSH runs on a custom port (e.g. 2222):


sudo ufw allow 2222/tcp



🌐 Step 4: Allow Other Ports (Web, Game, App, etc.)​


Examples:


  • Web server (HTTP + HTTPS):

sudo ufw allow 80,443/tcp

  • Minecraft server:

sudo ufw allow 25565

  • CS2 or custom UDP ports:

sudo ufw allow 27015/udp

  • MySQL (if remote access is required):

sudo ufw allow 3306

Customize this based on your app, panel, or game server setup.




✅ Step 5: Enable the Firewall​


Once your rules are in place:


sudo ufw enable

You’ll see:


“Command may disrupt existing ssh connections. Proceed with operation (y|n)?”

Type y and press Enter.


Your firewall is now active!




🔎 Step 6: Check Firewall Status​


To view current rules:


sudo ufw status verbose

To see open ports and rules in detail:


sudo ufw show raw



🔄 Bonus: Advanced UFW Usage​


Allow a specific IP (e.g. admin panel access only):


sudo ufw allow from 192.168.1.10

Block a specific IP:


sudo ufw deny from 203.0.113.45

Remove a rule:


sudo ufw delete allow 25565

Disable UFW temporarily:


sudo ufw disable



🧠 Final Tips​


  • Only open the ports you actually use
  • Keep UFW enabled at all times
  • Pair UFW with fail2ban for brute-force protection
  • Add UFW setup into your server provisioning checklist
  • Use Vastrox deployment templates to automate firewall configurations securely



🚀 Need Simpler Security for Your Servers?​


At Vastrox.com, our infrastructure tools are built with security in mind:


• Pre-configured UFW firewalls
• Global DDoS protection
• DNS & reverse proxy integration
• Auto-hardening during deployment


Whether you’re launching a web app, Minecraft server, or custom backend — we make Linux secure by default.




✅ Conclusion​


You’ve now secured your Linux server with UFW — an essential step in protecting your digital infrastructure. Whether you’re self-hosting or scaling up, managing firewalls should always be part of your workflow.


For more tutorials on Linux hardening, server optimization, and deployment automation, visit Vastrox.com.
 
Top