How to Enable or Disable UFW Firewall on Ubuntu

August 29, 2024

Introduction

Ubuntu comes pre-installed with a firewall configuration tool, Uncomplicated Firewall(UFW). UFW is easy to use and allows you to manage server firewall settings.

This tutorial shows you how to disable or enable a Ubuntu UFW firewall and how to check its status.

How to Enable or Disable UFW Firewall on Ubuntu

Prerequisites

  • A machine running Ubuntu (this tutorial uses Ubuntu 22.04).
  • Access to the terminal.
  • User with root or sudo privileges.

How to Check Ubuntu Firewall Status

Check the Ubuntu firewall status before turning it on or off to understand your system's current security settings. Additionally, this action avoids disrupting existing network configurations.

To check the status of the firewall, enter:

sudo ufw status
terminal output for sudo ufw status

The output shows the firewall is active.

How to Disable Ubuntu Firewall

A firewall is vital to network and server security. However, you might need to stop it while testing or troubleshooting. The following text explains how to stop the UFW service, disable it at boot, and uninstall it.

Stop UFW Service 

To stop UFW service, run the following command:

sudo systemctl stop ufw

The command does not produce an output but stops the UFW service immediately. This command does not affect whether it starts again at the next boot.

Disable UFW at Boot

There are two methods for disabling UFW at boot. They are similar but serve slightly different purposes.

One way to disable UFW at boot is with the following command:

sudo ufw disable
sudo ufw disable terminal output

This command stops UFW immediately and resets its status to inactive, meaning it does not filter traffic until re-enabled. The service is not automatically re-enabled at the next boot.

Another way to disable UFW at boot is with the following command:

sudo systemctl disable ufw
sudo systemctl disable ufw terminal output

The command prevents the UFW service from starting automatically at boot time. UFW does not start when the system boots, regardless of whether it was enabled or disabled before.

Uninstall UFW 

To completely remove UFW from your system, run the following command:

sudo apt remove ufw
terminal output for sudo apt remove ufw

How to Enable Ubuntu Firewall

Knowing how to enable a firewall is crucial for maintaining system security, preventing unauthorized access, and effectively managing network traffic.

To enable the firewall on Ubuntu, use the command:

sudo ufw enable
sudo ufw enable terminal output

The output confirms the firewall is once again active.

Conclusion

This tutorial explained how to enable or disable the firewall on Ubuntu. It also elaborated on how to check the UFW status.

Next, learn about different firewall types.

Was this article helpful?
YesNo
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
How To Set Up A Firewall With UFW On Ubuntu 18.04
September 12, 2024

UFW is a simple interface implemented on top of iptables that provides an easier way to configure a firewall. Use it to define rules of communication to and from a server and ensure your Ubuntu 18.04 is protected.
Read more
How To Enable And Use Firewalld On CentOS 7
September 4, 2019

This phoenixNAP guide instructs how to enable and start firewalld on CentOS 7. It explains basic firewall zone concepts and teaches you how to work with default firewalld zones.
Read more
How To Install Apache Tomcat 9 On Ubuntu 18.04
July 2, 2019

Apache Tomcat is a free, open-source, lightweight application server used for Java-based web applications. Developers use it to implement Java Servlet and JavaServer...
Read more
How To Install An FTP Server On Ubuntu With Vsftpd
January 4, 2024

FTP stands for File Transfer Protocol. It is similar to HTTP (HyperText Transfer Protocol), in that it specifies a language for transferring data over a network. FTP is...
Read more