How to list all iptables rules with line numbers on Linux

You can list all iptables rules with line numbers in Linux using the following command:

sudo iptables -nL --line-numbers

The -n option specifies that IP addresses and port numbers should be displayed in numeric format, rather than in reverse DNS format. The -L option lists all the rules in the specified table (the filter table, in this case). The --line-numbers option displays a line number for each rule in the list.

This will display a list of all the rules in the filter table, along with their line numbers, allowing you to easily refer to specific rules in the list.

Note that you’ll need to run this command with sudo in order to have the necessary permissions to view and manipulate iptables rules.

Leave a Comment