Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 727
Bruno Rijsman Avatar asked Dec 08 '08 13:12

Bruno Rijsman


People also ask

What option of netstat can be used to Display the status of all network interfaces?

The i option of the netstat command shows the state of the network interfaces that are configured on the local system. With this option, you can determine the number of packets a system transmits and receives on each network. Display the status of interfaces on the network.

How do I find my Ethernet interface name in Linux?

1. Log in to the system as root and run ifconfig -a plumb in a command shell. The command discovers all installed network interfaces.

What does IP link show do?

The ip link command allows you to modify the transmit queue, speeding up or slowing down interfaces to reflect your needs and hardware possibilities.


1 Answers

On my system, there are files under /sys/class/net/eth0/statistics, which gives various stats about network interfaces.

This is assuming a vaguely recent Linux which has /sys (sysfs) mounted.

like image 96
MarkR Avatar answered Nov 03 '22 00:11

MarkR