iptables counts packets and bytes of all network traffic that passes through it.
To list the packet and byte counters, execute the iptables -L command with the -v option.
By default, the iptables counters are reset after a system reboot, but you can also reset them manually using the -Z option and this note shows some examples how to do this.
Cool Tip: Monitor a network traffic in a real-time using iptables! Read more →
Reset IPTables Counters
To reset all the iptables counters:
$ sudo iptables -Z
To reset the packet and byte counters in the specific chain:
$ sudo iptables -Z <chainName>
- example-
$ sudo iptables -Z OUTPUT
To reset the statistics of the specific rule in the given chain:
$ sudo iptables -Z <chainName> <ruleNumber>"
- example-
$ sudo iptables -Z OUTPUT 5
To find out a rule number in the chain, execute:
$ sudo iptables -L <chainName> --line-numbers"
- example-
$ sudo iptables -L OUTPUT 5 --line-numbers
To reset all the counters and list the iptables rules just after:
$ sudo iptables -Z -L -v
Cool Tip: The best examples ever of a tcpdump command! Read more →
| Option | Description |
|---|---|
-Z, --zero |
Zero the packet and byte counters in all the chains, or only the given chain, or only the given rule in a chain. |
-L, --list |
List all rules in the selected chain. If no chain is selected, all the chains are listed. |
-v, --verbose |
Verbose output. |
--line-numbers |
Add line numbers to the beginning of each rule, corresponding to that rule’s position in the chain. |
Cool Tip: How to disable iptables temporary! Read more →