Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install and Set Up UFW on Ubuntu 22.04

Install the Uncomplicated Firewall, turn it on and add your first rules.

Firewall1 min read3 steps11 screenshots

Method 1: Install UFW from the terminal

Step 1: Open a terminal

Opening the Ubuntu terminal

Step 2: Update the package list

sudo apt update
Updating the packages

Step 3: Install UFW

sudo apt install ufw
Installing UFW

Step 4: Check the status

sudo ufw status
The UFW status

Step 5: Turn on UFW

Warning: Allow SSH before you enable UFW on a remote server, or you will lock yourself out.
sudo ufw allow ssh
sudo ufw enable
Enabling UFW
UFW is active

Method 2: Install from the Software Center

  1. Open Ubuntu Software.
    Ubuntu Software
  2. Search for UFW or a GUI such as GUFW.
    Finding Uncomplicated Firewall
  3. Click Install.
    Installing the firewall

Set up rules

Allow SSH:

sudo ufw allow ssh
Allowing SSH

Block a port:

sudo ufw deny 80
Blocking port 80

Set the default rules, deny all incoming and allow all outgoing:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Show the rules with numbers:

sudo ufw status numbered

Why choose UFW

  • Easy. Short, readable commands.
  • Built in. It is part of Ubuntu.
  • Works with iptables in the background.
  • Safe by default. Deny incoming, allow outgoing.

Quick recap

  • Install, allow SSH, then enable.
  • Add rules with allow and deny.