Back to all articles
Security

Setting Up a Firewall with UFW on Ubuntu

A comprehensive guide to configuring UFW (Uncomplicated Firewall) to protect your Linux server from unwanted traffic.

January 14, 2025
10 min read

Setting Up a Firewall with UFW on Ubuntu

UFW (Uncomplicated Firewall) is a user-friendly interface for managing firewall rules on Ubuntu and Debian systems. This guide will help you set up and configure UFW to protect your Linux server.

Why You Need a Firewall

A firewall acts as a barrier between your Linux server and the internet, controlling which network traffic is allowed in and out.

Step 1: Check UFW Status

First, check if UFW is installed:

sudo ufw status verbose

If UFW isn't installed:

sudo apt update
sudo apt install ufw

Step 2: Set Default Policies

Configure UFW to deny all incoming traffic and allow all outgoing traffic:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Step 3: Allow SSH (Critical!)

Before enabling UFW, allow SSH connections or you'll lock yourself out:
sudo ufw allow ssh

Or specify the port explicitly:

sudo ufw allow 22/tcp

Step 4: Allow Common Services

Allow the services you need:

Web Server (HTTP/HTTPS)

sudo ufw allow http    # Port 80
sudo ufw allow https   # Port 443

Step 5: Enable UFW

Once you've configured your rules, enable UFW:

sudo ufw enable

Step 6: Verify Configuration

Check your firewall status and rules:

sudo ufw status numbered

Conclusion

You've now configured a secure firewall using UFW! Combined with Gumpbox's intuitive interface, managing your Linux server security becomes effortless.

Next Steps

Ready to simplify your Linux server management?

Gumpbox makes server administration effortless with an intuitive interface designed for developers.

Get Started