The iptables is the simplest and most powerful Linux command used to manage network traffic with several options. Different rules define the behavior of the network traffic in Linux. The iptables rules are instructions for managing incoming and outgoing network traffic.
In this blog, different methods to list down the rules of the iptables have been explored, and the contents of this blog are:
- How to List All iptables Rules on Linux?
- Listing Rules by Specification
- Listing a Specific Chain
- Listing Rules as Tables
- Displays the Packet Count and Aggregate Size
- Display the iptables Output with Multiple Options
- List all the IPv4 Rules
- List All the IPv6 Rules
Let’s start the blog by displaying the installed version of the iptables command utility.
Prerequisite: Check the Availability of iptables
In most of the Linux distributions, the iptables command utility comes pre-installed, which can be verified using the command:
$ iptables --version
The “iptables” version has been displayed, but in case it is not pre-installed, then you can install it using the command:
Linux Distributions | Command |
---|---|
Debian-based | $ sudo apt install iptables |
Fedora/RHEL-based | $ sudo dnf install iptables |
When the installation of the “iptables” has been confirming, then we will proceed the next section of listing down the iptables rules in Linux.
How to List All iptables Rules on Linux?
Different options are used to list down the different iptables rules in Linux. We will explore all these methods by executing the different commands. Before that, we will see the general syntax of using the iptables command:
$ sudo iptables [options]
The iptables command is used either as the root user or with the sudo privileges. Then we can run the iptables command with its different options. The options which are used to list down the rules are explained in the next section.
Listing Rules by Specification
If you want to list down the iptables rules with its specification, then you have to use the “S” option:
$ sudo iptables -S
We can see that the rules have been displayed with specifications on Linux.
Listing a Specific Chain
We have seen that the output of the above command contains all the chains of the defined rule. But if we want to limit the displayed output of the specification to a certain parameter, for example, to the “INPUT,” use the command:
$ sudo iptables -S INPUT
The above command displayed the rules of the iptables with the “INPUT”.
Listing Rules as Tables
Another method to display the iptables rules is using the “L” option in the table format. For example, we run the command:
$ sudo iptables -L
Like the chain option with the specification, we can also list down the rules in the tabular form using the chain option:
$ sudo iptables -L INPUT
In the above output, some options are used whose explanation is:
Options | Explanation |
---|---|
target | If the packet is matched with the rule, the target option specified the behavior of the implemented on the packet |
prot | Displays the protocol such as TCP |
opt | This displays the ip address options |
source | Displays the ip address of the source |
destination | Displays the destination ip address |
Displays the Packet Count and Aggregate Size
Another method is to display some additional information which contains the “Packet Count” and the “Aggregate Size” with the command:
$ sudo iptables -L INPUT -v
The number of the packets and their size have been displayed on the screen.
Display the iptables Output with Multiple Options
We can use multiple options in a single command; for example, we used the command:
$ sudo iptables -L -n -v -t | more
The explanation of the options used in the above command is:
Options | Explanation |
---|---|
L | List down the rules in the table format |
n | Displays the numeric output of Ip address |
v | Displays the verbose mode |
more | Displays all the other options of the iptables |
List all the IPv4 Rules
To display all the IPv4 rules in Linux with the iptables command, use the command:
$ sudo iptables -S
List All the IPv6 Rules
To display all the IPv6 rules with the iptables command:
$ sudo ip6tables -S
These are all the methods to list all iptables rules on Linux.
Conclusion
To list all the iptables rules on Linux, run the command “sudo iptables -L -n -v | more”. The iptables contain several options by which we can manage the incoming and outgoing network traffic on a Linux firewall. In this blog, different commands have been explained, with the help of which we can list down all the iptables rules on Linux.