Configure firewall

Description

In this guide, you will learn how to configure a basic firewall using the firewall application UFW (uncomplicated firewall).

We are using the Linux operating system Ubuntu 24.04.

What you’ll learn
  • Install and configure UFW.
  • Set default incoming and outgoing traffic policies.
  • Allow SSH connections.
  • Enable, verify and reload the firewall.
Step by step guide
1# Install UFW
2apt install ufw -y
3 
4# Check firewall status
5ufw status
6 
7# Set default policies
8ufw default deny incoming
9ufw default allow outgoing
10 
11# Allow SSH connections
12ufw allow 22/tcp comment 'SSH'
13 
14# Enable the firewall
15ufw --force enable
16 
17# Check firewall configuration
18ufw status verbose
19 
20# Reload firewall rules
21ufw reload
Next steps