Iptables, in Linux-based systems, are used for managing network traffic. These are the rules that control outgoing and incoming traffic, ensuring network security.
You can keep networks safe by allowing only authorized traffic by inspecting them through the listing. Additionally, you can delete unwanted IPTables and firewall rules from your Ubuntu system.
This post aims to explain how to list the Iptables and Firewall rules and delete them to manage network traffic on your Ubuntu 22.04 system.
How to List and Delete Iptables and Firewall Rules?
This post will explain the following sections:
- How to List Iptables and Firewall Rules?
- How to Delete Iptables and Firewall Rules?
- How to Delete the User-defined Iptables and Firewall Rules?
How to List Iptables and Firewall Rules?
To view the list of Iptables and Firewall rules, the following are some useful commands.
Step 1: List Iptables Rules
Here is the simple command that will list the current iptables rules configured on your Ubuntu machine:
sudo iptables -L |
In response to the above command, a list of Iptables rules will be displayed under the three main categories: INPUT, FORWARD, and OUTPUT.
Step 2: List Iptables Rules with Details
For a more detailed view of the IPTables rules, including packets and bytes, use the additional -v flag with the command:
sudo iptables -L -v |
Here you can examine the packet counts and bytes for each rule in Iptables.
Step 3: List Specific (OUTPUT) Iptables Rules
If you are looking for a specific Iptables rule, such as OUTPUT, execute the below-mentioned command:
sudo iptables -L OUTPUT -v |
As you can see the OUTPUT option listed only the rules specified in the OUTPUT category.
Step 4: List Rules with Line Numbers
For a better representation of the rules list, you can add a reference number using the simple command:
sudo iptables -L --line-numbers |
With serial or reference numbers, it is easy to inspect the Iptables rules.
Step 5: List Rules with Lines and Numeric Values
By adding the -n flag to the Iptables command, you can see numerical output rather than names. Use the given-below command:
sudo iptables -L -n --line-numbers |
The command displayed the sources and destinations numerically rather than by their hostnames or service names.
Here, we experienced different commands for listing the Iptables and Firewall rules on the Ubuntu 22.04 machine.
How to Delete Iptables and Firewall Rules?
These commands will delete the Iptables and Firewall rules from your Ubuntu 22.04 system.
Step 1: List the Rules with Line Numbers
Before deleting Iptables rules, first, inspect the list of rules using the command:
sudo iptables -L --line-numbers |
Step 2: Delete Specific Rule
To delete a specific rule such as reference number 4 under the INPUT chain, use the command:
sudo iptables -D INPUT 4 |
Step 3: Verify List After Deleted Rules
After deleting a rule, you can confirm the changes by listing the rules in the terminal:
sudo iptables -L --line-numbers |
If the specific rule (i.e., INPUT 4) no longer exists in your IPTables list, it indicates that the rule has been deleted successfully.
How to Delete the User-defined Iptables and Firewall Rules?
This section will explore commands for deleting Iptables and Firewall rules, particularly the user-defined rules, from your Ubuntu system.
Step 1: List User-defined Rules
First of all, run the list command to identify the user-defined chains and rules:
sudo iptables -L --line-numbers |
In this example, you can see a chain and rules with the name “KARIM”.
Step 2: Delete Chains Associated with User-defined
Now, let’s delete the rules first, which are associated with “KARIM”. Specify the chain and rule number using the following syntax to delete the rules:
sudo iptables -D FORWARD 2 |
Step 3: Delete User-defined Rules
Finally, use the -X option to delete the user-defined chain like “KARIM” :
sudo iptables -X KARIM |
Step 4: Verify Iptables Rules After Deletion
Use the list command to verify whether the user-defined rules (i.e. KARIM) have been deleted from the Iptables rules:
sudo iptables -L --line-numbers |
It can be seen that the chain and rules associated with KARIM no longer exist.
In this section, we have explored different commands to delete the Iptables and Firewall rules from your Ubuntu 22.04 system.
Conclusion
In Ubuntu, you can inspect the list of Iptables and delete them using simple commands. The command, sudo iptables -L will display the list, while deleting the Iptable chain and rules, use sudo iptables -D. This post has provided some useful commands to list and delete Iptables and Firewall rules from the Ubuntu 22.04 system.
Leave feedback about this