Here’s a step-by-step guide to list and delete UFW (Uncomplicated Firewall) rules on an Nginx web server:
Prerequisites:
- You need root or sudo privileges to manage UFW.
- UFW should be installed and active on your system.
Step 1: List UFW Firewall Rules
- Open Terminal:
- Access your server through SSH or directly open a terminal.
- Check UFW Status:
- Before listing rules, ensure UFW is active.
sudo ufw status
- If UFW is inactive, you’ll see “Status: inactive”. You need to enable it first if you plan to manage the rules.
sudo ufw enable
- List UFW Rules:
- To list all current UFW rules, use the following command:
sudo ufw status numbered
- This command will show all the rules with their corresponding numbers, making it easier to manage them. The output will look something like this:

Step 2: Delete UFW Firewall Rules
- Identify the Rule to Delete:
- From the output above, decide which rule(s) you want to delete. Note the corresponding number for each rule.
- Delete the Rule by Number:
- To delete a rule, use the following syntax, replacing
X
with the rule number.
sudo ufw delete X
- For example, to delete the rule number
3
(allowing traffic on port 8080), you would run:
sudo ufw delete 3
- Confirm Deletion:
- After running the delete command, UFW will prompt you to confirm the deletion. Type
y
to confirm.

- Verify Deletion:
- List the UFW rules again to ensure the rule has been successfully deleted.
sudo ufw status numbered
Step 3: Manage UFW Rules as Needed
- Add New Rules:
- If you need to add new rules, you can use the
allow
ordeny
commands:
sudo ufw allow 80/tcp
sudo ufw deny 8080/tcp
- Reload UFW (if necessary):
- Sometimes, after adding or deleting rules, it may be necessary to reload UFW for the changes to take effect.
sudo ufw reload
Step 4: Disable UFW (Optional)
- Disable UFW:
- If you need to temporarily or permanently disable UFW, use the following command:
sudo ufw disable
- You can re-enable it later with:
sudo ufw enable
Conclusion
This guide walks you through the steps to list and delete UFW firewall rules on an Nginx web server. Always ensure that you manage firewall rules carefully to maintain the security of your server.
Leave a Reply