Skip to content
Advertisement

Linux: retrieve per-interface sent/received packet counters (ethernet, ipv4, ipv6)

On Linux, how can I (programmatically) retrieve the following counters on a per-interface basis:

  • Sent/received ethernet frames,
  • Sent/received IPv4 packets,
  • Sent/received IPv6 packets.

Advertisement

Answer

You should be able to do this using iptables rules and packet counters, e.g.

JavaScript

And to view the stats, parse the output of these:

JavaScript

You should also look up the -Z flag for when you want to reset the counters.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement