On Linux, each network interface comes with several packet counters such as RX (number of received packets), TX (number of transmitted packets), errors (number of packets with errors), dropped (number of dropped packets) and overruns (number of lost packets due to queue overrun). You can inspect these packet counters either by running ifconfig command or by inspecting /proc/net/dev. These counters keep incrementing over time until they wrap around. If, for some reason, you want to reset those counters at any time, here is what you can do.
First, you must understand that you cannot reset the packet counters while the NIC is being used. Since these packet counters are maintained by a NIC driver, you can reset the counters by disabling and reloading the NIC driver.
In this example, let's reset the packet counters for a network interface named p1p2.
First, you need to identify which NIC driver is associated with p1p2 interface.
The following command will help you find that out. It will show detailed information of existing Ethernet interfaces, including assigned interface name and an associated NIC driver.
In this example, the interface p1p2 is managed by a driver named ixgbe.
Check if the driver is currently loaded in the kernel.
ixgbe 236327 0 dca 15232 1 ixgbe ptp 18627 1 ixgbe mdio 13807 1 ixgbe
Now go ahead and disable the driver by using modprobe command. Be aware that if you are connected remotely to this machine through the interface managed by the driver, you will lose the connection. So be careful!
The following command will remove the driver from the kernel.
Verify that the driver is successfully removed by issuing the command below. If the driver is unloaded safely, the command should not display any output.
Go ahead and re-enable the driver by using modprobe command.
At this point, the RX/TX and all other counters of the interface p1p2 should be successfully reset.
NOTE: In this example, we assume that the NIC driver exists as a loadable kernel module. However, some NIC drivers are built into the kernel, in which case you cannot disable the module as described in this tutorial. To check if the NIC driver is kernel built-in, use modprobe command.
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!