How to Turn off UFW Firewall in Ubuntu

Troubleshooting an issue and want to disable the firewall temporarily? Or do you want to disable it permanently? Here's what you should do in Ubuntu.

Firewalls are double edged swards. They protect your server from unwanted traffic (attacks) but a misconfigured firewall can also cause trouble running your usual web services.

If you are troubleshooting an issue and need to turn off the firewall in Ubuntu, you can use the following command:

sudo ufw disable

This will disable the firewall in Ubuntu until you manually turn it on again:

sudo ufw enable

Let's see it in detail.

Turn off the Firewall in Ubuntu

So the first step is to check the status of the firewall:

sudo ufw status

And it should be active (that's the reason why you're here. Isn't it?)

[email protected]:~$ sudo ufw status
Status: active

Similarly, you can also use verbose option for more detailed output:

[email protected]:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere                  
2222                       ALLOW IN    Anywhere                  
22/tcp (v6)                ALLOW IN    Anywhere (v6)             
2222 (v6)                  ALLOW IN    Anywhere (v6)             

Now, if you want to stop the firewall temporarily, you can use the given command:

sudo systemctl stop ufw 
check ufw firewall status in ubuntu

The permanent solution:

I won't recommend disabling the firewall permanently even if you have hardware-level protection as it protects individual servers.

First, let's disable the firewall using the disable arguement with the ufw command:

sudo ufw disable

You can also use the systemd to stop the ufw firewall from getting started on each boot using the given command:

sudo systemctl disable ufw

Enable Firewall again

If you consider using the firewall again, here's how you do it.

First, to enable the firewall, you'd have to use the enable argument with the ufw command:

sudo ufw enable

And if you disabled the ufw to start itself on every boot, you can alter that behavior using the given command:

sudo systemctl enable ufw

Reboot your system and your firewall will be back to life!

enable ufw firewall in ubuntu

Wrapping Up

If you are troubleshooting an issue with a particular application or you want certain services to get unrestricted access, you can allow selected ports through UFW. This way, you'll have the security of the firewall in place.

And if you have any queries, let me know in the comments.

Linux Foundation Training