You can list iptables
rules with rule numbers using the
--line-numbers
option, but this only works in list (-L
) mode. I
find it much more convenient to view rules using the output from
iptables -S
or iptables-save
.
You can augment the output from these commands with rule numbers with
the following awk
script:
#!/bin/awk -f
state == 0 && /^-A/ {state=1; chain=$2; counter=1; printf "\n"}
state == 1 && $2 != chain {chain=$2; counter=1; printf "\n"}
!/^-A/ {state=0}
state == 1 {printf "[%03d] %s\n", counter++, $0}
state == 0 {print}
This will produce output along the lines of: