How to reset RX/TX counters of a network interface

Question: I am testing a network interface card (NIC), and currently ifconfig command reports huge numbers on RX/TX and error/dropped counters on some interface. Is there a way to reset ifconfig packet counters on a network interface without rebooting the server?

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.

$ sudo lshw -class network

In this example, the interface p1p2 is managed by a driver named ixgbe.

Check if the driver is currently loaded in the kernel.

$ lsmod | grep ixgbe
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.

$ sudo modprobe -r ixgbe

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.

$ lsmod | grep ixgbe

Go ahead and re-enable the driver by using modprobe command.

$ sudo modprobe ixgbe

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.

$ modprobe -D lzo_compress
builtin lzo_compress
Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

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.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

One thought on “How to reset RX/TX counters of a network interface

  1. Nice, but this causes the network connection to be disprupted. If I don't have physical access to the system I can't reset it without me being cut off. Isn't there another way to achieve it?

Leave a comment

Your email address will not be published. Required fields are marked *