How to Enable/Disable UFW Firewall on Ubuntu 18.04 & 20.04

August 18, 2019

Introduction

Ubuntu comes pre-installed with a firewall configuration tool, UFW (Uncomplicated Firewall). UFW is easy to use for managing server firewall settings.

This tutorial shows you how to disable and enable an Ubuntu UFW firewall using the command line.

How to enable or disable the UFW firewall on Ubuntu.

Prerequsites

  • A machine running Ubuntu 18.04, 20.04, or 22.04.
  • Command line / terminal window
  • User with root or sudo privileges

Check Ubuntu Firewall Status

Before disabling the UFW firewall, it is a good idea to check its status first. In Ubuntu, the firewall is disabled by default. How do you know if your firewall is on?

To check the current status of the firewall, execute the command in your command terminal:

sudo ufw status

In this example below, the output shows that the firewall is active.

ufw firewall is active on this system

As we have determined the current state, now we can proceed to disable the UFW firewall.

Disable Ubuntu Firewall

A firewall is a vital element in a network and server security. However, while testing or troubleshooting, you might need to shut down or stop the firewall.

To disable the firewall on Ubuntu, enter:

sudo ufw disable

The terminal informs you that the service is no longer active.

example of firewall disabled and stopped on system startup

If you disable the firewall, keep in mind that your firewall rules are still in place. Once you enable the firewall again, the same rules that were set up prior to the deactivation will apply.

Enable Firewall

Learning how to enable the firewall on Ubuntu is vital.

To enable the firewall on Ubuntu, use the command:

sudo ufw enable
screenshot of code after enabling the firewall in Ubuntu

As with the ‘disable’ command, the output confirms that the firewall is once again active.

Using UFW to Set Firewall Rules

UFW does not provide complete firewall functionality via its command-line interface. However, it does offer an easy way to add or remove simple rules.

A good example is opening an SSH port.

For example:

sudo ufw allow 22

Once the terminal confirms that the rule is now in place, check the status of the firewall with the ‘status’ command:

sudo ufw status

The output is going to reflect the fact that an SSH port is now open.

ssh port is open when checking status

Reseting UFW Firewall Rules

If you need to reset all rules back to default settings, use the reset command:

sudo ufw reset

After confirming the action, by typing y, the firewall settings revert to their default values.

resetting firewall rules with sudo command

Conclusion

In this guide, you learned how to disable and stop the firewall on Ubuntu. We also showed you how to enable the firewall and reset settings.

Now you know the options available with the UFW tool. These commands provide an excellent foundation to explore firewall functions and settings.

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
December 1, 2022

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
June 6, 2019

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