sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Set Up a Firewall with UFW on Ubuntu 22.04
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Set Up a Firewall with UFW on Ubuntu 22.04

Samuel Siahaan
By Samuel Siahaan
Last updated: September 11, 2023
SHARE

If you’re concerned about the security of your Ubuntu 22.04 system, setting up a firewall is a crucial step to protect your data and keep potential threats at bay. In this article, we will show you how to set up a firewall with UFW on Ubuntu 22.04, using familiar words and simple explanations.

Contents
Table of ContentsWhat is a Firewall?Why UFW on Ubuntu 22.04?Step 1: Open a Terminal you Ubuntu 22.04Step 2: Check UFW Status on Ubuntu 22.04Step 3: Enable UFW on Ubuntu 22.04Step 4: Configure Default PoliciesStep 5: Allow SSH AccessStep 6: Allow Other ServicesStep 7: Check the RulesStep 8: Delete or Disable RulesStep 9: Reload UFW on Ubuntu 22.04Step 10: Check UFW Status AgainConclusion

Table of Contents

  • What is a Firewall?
  • Why UFW on Ubuntu 22.04?
    • Step 1: Open a Terminal you Ubuntu 22.04
    • Step 2: Check UFW Status on Ubuntu 22.04
    • Step 3: Enable UFW on Ubuntu 22.04
    • Step 4: Configure Default Policies
    • Step 5: Allow SSH Access
    • Step 6: Allow Other Services
    • Step 7: Check the Rules
    • Step 8: Delete or Disable Rules
    • Step 9: Reload UFW on Ubuntu 22.04
    • Step 10: Check UFW Status Again
  • Conclusion

What is a Firewall?

Before diving into the setup process, let’s briefly understand what a firewall is and why you need one. A firewall acts as a barrier between your computer and the outside world, controlling incoming and outgoing network traffic based on a set of rules. It helps prevent unauthorized access and safeguards your system from malicious activities.

Why UFW on Ubuntu 22.04?

Ubuntu 22.04 comes with UFW pre-installed, making it an excellent choice for setting up a firewall. UFW is known for its simplicity and user-friendly interface, making it accessible even for beginners.

Now, let’s get started with the step-by-step process:

- Advertisement -

Step 1: Open a Terminal you Ubuntu 22.04

First, open a terminal on your Ubuntu 22.04 system. You can do this by pressing Ctrl+Alt+T or searching for “Terminal” in the applications menu.

Step 2: Check UFW Status on Ubuntu 22.04

To check if UFW is already enabled on Ubuntu 22.04, type the following command:

Bash
$ sudo ufw status

If UFW is not enabled, you will see a message indicating that the firewall is inactive.

Step 3: Enable UFW on Ubuntu 22.04

To enable UFW on Ubuntu 22.04, use the following command:

Bash
$ sudo ufw enable

You’ll be prompted to enter your sudo password. Afterward, confirm the action by typing ‘y’ and pressing Enter.

- Advertisement -

Step 4: Configure Default Policies

By default, on Ubuntu 22.04 UFW denies all incoming and outgoing traffic. You can change these settings based on your needs. Here are some common configurations:

Allow all outgoing traffic:

Bash
$ sudo ufw default allow outgoing

Block all outgoing traffic:

- Advertisement -
Bash
$ sudo ufw default deny outgoing

Allow all incoming traffic:

Bash
$ sudo ufw default allow incoming

Block all incoming traffic:

Bash
$ sudo ufw default deny incoming

Choose the configuration that best suits your security requirements.

Step 5: Allow SSH Access

If you’re using SSH to access your Ubuntu 22.04 system remotely, you should allow SSH traffic. Use the following command to do so:

Bash
$ sudo ufw allow OpenSSH

This will enable SSH access on the default port 22.

Step 6: Allow Other Services

Depending on your server’s setup, you may need to allow other services or applications to function correctly. For example, to enable web traffic, use:

Bash
$ sudo ufw allow 'Apache Full'

Or for a database server:

Bash
$ sudo ufw allow 'MySQL'

Be sure to specify the service name correctly.

Step 7: Check the Rules

To see a list of rules you’ve added, run:

Bash
$ sudo ufw status numbered

This will display a numbered list of the firewall rules.

Step 8: Delete or Disable Rules

If you need to delete or disable a rule, you can do so using the following commands:

To delete a rule by its number:

Bash
$ sudo ufw delete [rule number]

To disable a rule by its number:

Bash
$ sudo ufw disable [rule number]

Step 9: Reload UFW on Ubuntu 22.04

After making changes to your firewall rules, reload UFW to apply the updates:

Bash
$ sudo ufw reload

Step 10: Check UFW Status Again

To ensure that your firewall is properly configured and active on your Ubuntu 22.04, run:

Bash
$ sudo ufw status

Conclusion

Congratulations! You’ve successfully set up a firewall using UFW on your Ubuntu 22.04 system. By following these steps and configuring your firewall to suit your specific needs, you’ve taken a significant step toward enhancing the security of your system.

Remember, a well-configured firewall is a critical component of your overall system security. Regularly review and update your firewall rules to adapt to changing security requirements.

In this guide, we’ve covered the basics of setting up a firewall with UFW on Ubuntu 22.04, using familiar words and clear explanations. Now, you can enjoy improved protection for your Ubuntu system.

Also Read Our Other Guides :

  • How To Set Up a Firewall Using FirewallD on CentOS 7
  • How To Set Up a Firewall Using FirewallD on Rocky Linux 9
  • How To Set Up a Firewall with UFW on Debian 11
  • Initial Setup Debian 11 Server: Secure and Efficient
  • Initial Setup Ubuntu Server 22.04: Secure and Efficient
  • Initial Setup Rocky Linux 9 Server: Secure and Efficient
  • How To Install Ubuntu Server 22.04 LTS with Screenshots
  • How To Install Uptime Kuma on Ubuntu 22.04

Finally, now you have learned how to set up a firewall using Uncomplicated Firewall (UFW) on Ubuntu 22.04.

TAGGED:FirewallSecurityServer GuideUbuntuUFW

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Initial Setup CentOS 7 Server: Secure and Efficient
Next Article How To Set Up a Firewall Using FirewallD on CentOS 7
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Linux

How To Install and Use Linux Screen with Commands

9 Min Read
Rocky Linux

How To Secure SSH with Fail2Ban on Rocky Linux 9

12 Min Read
Ubuntu

How To Install PHP 8.2 on Ubuntu Server 22.04

11 Min Read
Ubuntu

How To Install VirtualBox 7.0 on Ubuntu 22.04

9 Min Read
CentOS

Initial Setup CentOS 7 Server: Secure and Efficient

9 Min Read
Ubuntu

How To Install MongoDB 6.0 on Ubuntu Server 22.04

10 Min Read
Ubuntu

How To Install MariaDB 10.6 on Ubuntu Server 22.04

14 Min Read
Ubuntu

How To Install MySQL 8.0 on Ubuntu Server 22.04

20 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?