How to Disable (or Enable) Firewall in Ubuntu 20.04

Ubuntu comes with ufw (uncomplicated firewall) installed by default. This is a frontend for iptables/nftables, the built-in Linux firewall, and is meant to make firewall management a bit easier.

Stop/Disable Firewall in Ubuntu

If you find the Ubuntu firewall interfering with connections on your system, one option is to disable the firewall completely.

Warning: it’s recommended that you add custom firewall rules to allow certain ports and access through the firewall, rather than disabling the firewall completely.

1. To turn off the Ubuntu firewall, use the following command in terminal.

$ sudo ufw disable
Firewall stopped and disabled on system startup

As seen from the output, the command will also disable the firewall from starting automatically upon system reboots.

2. To delete all configured ufw rules and set the firewall back to default settings, execute the ufw reset command.

$ sudo ufw reset
Resetting all rules to installed defaults. Proceed with operation (y|n)? y

3. You can also use iptables commands to bypass the ufw interface and interact directly with the system firewall. The following commands will clear every configured chain and rule in your firewall. This is only recommended if the commands above don’t fix your issue.

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X

Start/Enable Firewall in Ubuntu

1. To revert the changes made above, you can turn the firewall back on with the following command. This will also cause it to start automatically whenever Ubuntu reboots.

$ sudo ufw enable
Firewall is active and enabled on system startup

Check Status of Ubuntu Firewall

1. You can always check to see if ufw is on or off by using this command to check the service’s status. This will also show what rules are currently configured in the firewall.

$ sudo ufw status
Status: active

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

2. Once again, we can use the iptables command to interact directly with the system firewall, but it’s not as user friendly. This command will list all configured firewall rules.

$ sudo iptables -L

Leave a Comment

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