Techolac - Computer Technology News
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
Techolac - Computer Technology News
No Result
View All Result
Home Linux

How to delete a UFW firewall rule on Ubuntu, Debian Linux

by Editorial Staff
July 17, 2019
in Linux
Reading Time: 5 mins read

How do I remove and delete a UFW firewall rule running on Ubuntu or Debian Linux?

UFW is an acronym for an uncomplicated firewall. Securing a network with the uncomplicated firewall is super easy. The Ubuntu Linux comes with packet filtering called Netfilter. The iptables frontend command used to manage netfilter. However, ufw provides easy to use front-end for netfilter, and it is one of the most popular among Ubuntu and Debian Linux sysadmins and developers. This page shows how to remove a UFW firewall rule.

Adblock detected 😱
My website is made possible by displaying online advertisements to my visitors. I get it! Ads are annoying but they help keep this website running. It is hard to keep the site running and producing new content when so many people block ads. Please consider donating money to the nixCraft via PayPal/Bitcoin, or become a supporter using Patreon.

 

Procedure to list and delete UFW firewall rules

  1. Log in to server
  2. Display firewall rules, run: sudo ufw status numbered
  3. Delete a ufw firewall rule by rule number # 3: sudo ufw delete 3
  4. Another option to erase a firewall rul is to run: sudo ufw delete allow 22/tcp

Let us see all examples in details.

Warning: Be careful working with firewalls; take care not to lock yourself out of ssh session when deleting rules.

How to list UFW firewall rules

To list and show firewall status, run:
sudo ufw status
Sample outputs:

Status: active
 
To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere                  
25/tcp                     ALLOW       Anywhere                   # accept email
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
22/tcp (v6)                ALLOW       Anywhere (v6)             
25/tcp (v6)                ALLOW       Anywhere (v6)              # accept email
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)

Status: active To Action From
— —— —-
22/tcp ALLOW Anywhere
25/tcp ALLOW Anywhere # accept email
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
25/tcp (v6) ALLOW Anywhere (v6) # accept email
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)

See also  Top Best Text Editors for Linux Programming in 2021

It is possible to see firewall status as numbered list of RULES, enter:
sudo ufw status numbered
Further one can display verbose firewall status, run:
sudo ufw status verbose

Listing UFW rules on Ubuntu or Debian Linux
Listing UFW rules

How to delete a UFW firewall rule

Now you know how to list rules. It is time to delete rules. There are two methotds to delete UFW rules.

Method # 1. Deleting UFW rules by rule number

First list the rules along with line number:
sudo ufw status numbered
Sample outputs shows list of all my UFW rules and their numbers in first column:

Status: active
 
     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    Anywhere                  
[ 2] 25/tcp                     ALLOW IN    Anywhere                   # accept email
[ 3] 80/tcp                     ALLOW IN    Anywhere                  
[ 4] 443/tcp                    ALLOW IN    Anywhere                  
[ 5] 22/tcp (v6)                ALLOW IN    Anywhere (v6)             
[ 6] 25/tcp (v6)                ALLOW IN    Anywhere (v6)              # accept email
[ 7] 80/tcp (v6)                ALLOW IN    Anywhere (v6)             
[ 8] 443/tcp (v6)               ALLOW IN    Anywhere (v6)

Status: active To Action From
— —— —-
[ 1] 22/tcp ALLOW IN Anywhere
[ 2] 25/tcp ALLOW IN Anywhere # accept email
[ 3] 80/tcp ALLOW IN Anywhere
[ 4] 443/tcp ALLOW IN Anywhere
[ 5] 22/tcp (v6) ALLOW IN Anywhere (v6)
[ 6] 25/tcp (v6) ALLOW IN Anywhere (v6) # accept email
[ 7] 80/tcp (v6) ALLOW IN Anywhere (v6)
[ 8] 443/tcp (v6) ALLOW IN Anywhere (v6)

Say you need to delete rule number 2 that opens tcp port 25 (email server), run:
sudo ufw delete {rule-number-here}
sudo ufw delete 2

You need to confirm ‘y’ when prompted to delete the rule from your system and verify it again:
sudo ufw status numbered
How to delete a UFW firewall rule on Linux

Method # 2. Removing UFW rules by ufw syntax

Say you added or open TCP port 80 and 443 using the following syntax:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw deny 23/tcp

You can delete those two rules using the following syntax (just prefix orignal rule with delete):
sudo ufw delete allow 80/tcp
sudo ufw delete allow 443/tcp
sudo ufw delete deny 23/tcp

Deleting a UFW Firewall Rule
Testing various commands that erased firewall rules

How do I disable ufw?

sudo ufw disable
To enable again, run:
sudo ufw enable

How do I reset ufw?

Want to disables and resets firewall to installation defaults? Try:
sudo ufw reset

Resetting all rules to installed defaults. This may disrupt existing ssh
connections. Proceed with operation (y|n)? y
Backing up 'user.rules' to '/etc/ufw/user.rules.20190714_171037'
Backing up 'before.rules' to '/etc/ufw/before.rules.20190714_171037'
Backing up 'user6.rules' to '/etc/ufw/user6.rules.20190714_171037'
Backing up 'after6.rules' to '/etc/ufw/after6.rules.20190714_171037'
Backing up 'before6.rules' to '/etc/ufw/before6.rules.20190714_171037'
Backing up 'after.rules' to '/etc/ufw/after.rules.20190714_171037'

Resetting all rules to installed defaults. This may disrupt existing ssh
connections. Proceed with operation (y|n)? y
Backing up ‘user.rules’ to ‘/etc/ufw/user.rules.20190714_171037’
Backing up ‘before.rules’ to ‘/etc/ufw/before.rules.20190714_171037’
Backing up ‘user6.rules’ to ‘/etc/ufw/user6.rules.20190714_171037’
Backing up ‘after6.rules’ to ‘/etc/ufw/after6.rules.20190714_171037’
Backing up ‘before6.rules’ to ‘/etc/ufw/before6.rules.20190714_171037’
Backing up ‘after.rules’ to ‘/etc/ufw/after.rules.20190714_171037’

See also  How to install htop on Ubuntu Linux using apt

Conclusion

This page demonstrated various ways to list and remove UFW firewall rules using the command line. Make sure you read ufw man page here and see our other pages below.

Related Posts

Top Commands to Check the Running Processes in Linux
Linux

Top Commands to Check the Running Processes in Linux

May 27, 2022
4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error
Linux

4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error

March 30, 2022
How Common Signals are Used in Kubernetes Pod Management
Linux

How Common Signals are Used in Kubernetes Pod Management

November 20, 2021

Leave a Reply Cancel reply

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

Top 26 Best NYAA Alternatives To Watch Anime Free

Top 26 Best NYAA Alternatives To Watch Anime Free

July 4, 2022
30 VUDU Alternatives To Watch Movies And TV Shows Online

30 VUDU Alternatives To Watch Movies And TV Shows Online

July 3, 2022
finland web hosting reviews

Top 10 Finland Web Hosting Reviews 2022

July 3, 2022
warehouse management systems software

Top 10 Best Warehouse Management Systems In 2022

July 2, 2022
Find Old Pensions and Boost Your Retirement Income

Find Old Pensions and Boost Your Retirement Income

July 2, 2022
  • DashTech
  • TechDaddy
  • Terms and Conditions
  • Disclaimer
  • Write for us

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

Go to mobile version