How to Enable or Disable Firewall on Ubuntu 24.04


A firewall is the protection shield around your server/any computing machine. It allows you to manage the incoming/outgoing traffic on your system, i.e., usually, it is used on servers where machines have to interact with it. You can set the custom rules or manage the pre-allocated ports to allow/deny the traffic. By doing so, your system is protected from malicious attempts. Most of the security breaches are effective if you have not configured the firewall properly on your system.

Today we are here to guide you on how to enable, disable, and manage the firewall on Ubuntu 24.04.

Outline:

How to Enable or Disable Firewall on Ubuntu 24.04

When talking about the firewall, can be managed through the command line and a GUI tool. Being a Linux geek, I recommend using the command line approach to enable, disable, or manage the firewall on Ubuntu. However, we will list all the possible methods to manage firewall rules.

Method 1: ufw Tool | Default Utility and Recommended

The ufw utility is the default firewall manager in Ubuntu (and other renowned Linux distros). If it is not installed on your Ubuntu, you can do it using the following command:

sudo apt install ufw

Let’s learn how you can enable and disable the firewall using the ufw:

  • Enable the Firewall

Use the “enable” option of the ufw utility to enable the firewall on Ubuntu 24.04:

sudo ufw enable

Reload the firewall rules/changes using the following command:

sudo ufw reload

  • Check the Status of the Firewall

After all, check the status of the firewall utility to confirm the changes:

sudo ufw status

Once the firewall is enabled and active, it will start acting the rules that you have added/or any defaults.

  • Disable the Firewall

Likewise enabling, the disable flag of the ufw utility disables the firewall:

sudo ufw disable

Note: Is there a tool that provides a Graphical User Interface to enable and disable the firewall? Yes, there is, which we will be discussing right now:

Method 2: GUFW Tool | GUI Replica of ufw

The gufw tool provides the front end of the ufw utility. It offers almost equal functionality when compared with the command line support of ufw. Let’s check how it works:

  • Install the Tool

The gufw is not installed by default, install it first using the command:

sudo apt install gufw

Once installed, the app can be launched from the applications menu:

Its launching requires sudo privileges:

  • Enable the Firewall

When launched, you will see a “Toggle Button”. Turn it ON to enable the firewall on Ubuntu 24.04. You can check the updated status at the footer as well:

  • Disable the Firewall

Similarly, turn off the toggle button to disable the firewall:

That’s how you can control the firewall from the gufw, an interactive GUI tool to manage the firewall on Ubuntu 24.04.

Tip: How to Manage Firewall on Ubuntu 24.04

It is recommended to manage the firewall using the ufw utility as it is the default and the most used one. We have listed some use cases of the ufw utility to manage the firewall:

Allow Traffic Through the Firewall

The ufw command enables you to allow the specific as well as all types of traffic towards your machine.

  • Allow Specific IP to Specific Port

For instance, the command below allows the TCP protocol from the specific IP to a specific port.

sudo ufw allow proto tcp from <ip-address> to any <port-number>
  • Allow All Types of Traffic (incoming/outgoing) on Specific Port
sudo ufw allow <port-number>
  • Other ufw Commands to Allow Traffic

Some other useful ufw commands to allow/enable the traffic are:

These were the basic and the most used commands related to the “allow” functionality.

Commands Description/Purpose
ufw allow <app-profile> Allow using an app profile, i.e., ‘Apache Full’
ufw allow <service-name> Service name, i.e., ssh, https,
ufw default allow outgoing/incoming/routed Allow all the incoming/outgoing/routed traffic. Use one option at a time.
sudo ufw allow in on <network-inetrface> from <ip-address> Allow the traffic on specific network interface

Deny Traffic Through the Firewall

Similarly, you can disallow/deny any incoming traffic from a specific machine. Here are the commands to manage it:

  • Deny Traffic on a Specific Port

The following deny command is used the most to disable/deny the traffic from the specific port:

sudo ufw deny <port-num>
  • Deny the Specific Rule

You can deny the traffic permitted through a specific rule number on the ufw:

sudo ufw deny <rule-num>
  • Other ufw Commands to Deny the Traffic

Here’s an extended list of the commands that are used to “deny” the traffic:

Commands Description/Purpose
ufw deny <app-profile> Deny using an app profile, i.e., ‘Apache Full’
ufw deny <service-name> Service name, i.e., ssh, https,
ufw default deny outgoing/incoming/routed Deny all the incoming/outgoing/routed traffic. Use one option at a time.
sudo ufw deny in on <network-inetrface> from <ip-address> Deny the traffic on specific network interfaces.

Not all, but these are the most used ufw allow/deny related commands.

List the Active Firewall Rules

The command lists the active rules with the rule numbers:

sudo ufw status numbered

The rule-number field assists in referring the rule to delete or apply any action.

Delete Firewall Rule

First, check the rule-number from the output of the command “ufw status numbered” and use the command:

sudo ufw delete <rule-number>

That’s how you can enable or disable the firewall on Ubuntu 24.04.

Bottom Line

The firewall decides which traffic to allow and which to block. This configuration is set by the user/administrator. This act allows you to protect your system better than the system with no firewall. Thus, today we have demonstrated the way to enable or disable the firewall on Ubuntu 24.04.

Not only just enabling/disabling, you have also learned the way to manage the firewall on Ubuntu 24.04.

Print Friendly, PDF & Email
Categories