How To Setup UFW Firewall on Ubuntu 22.04 LTS
In this tutorial, we will show you how to setup UFW Firewall on Ubuntu 22.04 LTS. For those of you who didn’t know, UFW (Uncomplicated Firewall) is an easy-to-use front-end for iptables that helps in managing firewall rules on Ubuntu systems. UFW is designed to be an easy-to-use command-line interface for configuring firewall settings, making it a popular choice for users who want to secure their Linux systems. With UFW, you can configure a variety of rules to allow or block traffic based on network protocols, IP addresses, ports, and more. UFW also supports the use of Application Profiles, which are pre-configured sets of firewall rules that can be applied to popular services like SSH, HTTP, and HTTPS.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the UFW Firewall on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for UFW Firewall.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Setup UFW Firewall on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade sudo apt install wget apt-transport-https gnupg2 software-properties-common
Step 2. Installing UFW Firewall on Ubuntu 22.04.
By default, the UFW Firewall is available on Ubuntu 22.04 base repository. If it is not already installed on your system, you can install it using the following command:
sudo apt install ufw
After the installation is complete, you can check the status of the UFW Firewall using the following command:
sudo ufw status
By default, UFW Firewall is disabled. You can enable it using the following command:
sudo ufw enable
Step 3. Setting up UFW Rules.
Before setting up any rules in UFW Firewall, it is recommended to allow all outgoing traffic and deny all incoming traffic. You can do this using the following commands:
sudo ufw default deny incoming sudo ufw default allow outgoing
Once setting the default rules, you can start adding specific rules for your applications and services. For example, to allow HTTP traffic on port 80, you can use the following command:
sudo ufw allow 80/tcp
Similarly, you can allow HTTPS traffic on port 443 using the following command:
sudo ufw allow 443/tcp
You can also allow specific IP addresses to access your server using UFW Firewall. For example, to allow access to your server from IP address 192.168.77.21, you can use the following command:
sudo ufw allow from 192.168.77.21
By default, UFW Firewall blocks SSH access. To allow SSH access, you can use the following commands:
sudo ufw allow ssh sudo ufw limit ssh
Congratulations! You have successfully installed UFW Firewall. Thanks for using this tutorial for setup UFW Firewall on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official Ubuntu website.