16

When i run ifconfig eth0 see following lines:

eth0      Link encap:Ethernet  HWaddr 08:00:27:42:81:a7  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe42:81a7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:66 errors:0 dropped:0 overruns:0 frame:0
          TX packets:212 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8001 (8.0 KB)  TX bytes:34004 (34.0 KB)

How can i reset these counters especially RX/TX packets?

2
  • 1
    While you may not want to do this, it worth noting that you can also just restart your computer. :)
    – Vreality
    Sep 20 '13 at 17:38
  • 6
    Yes you can reset counters by restarting your computer, but is it a good choice? Is it comfortable to close all programs and restart computer to just reset some counters? You suggest Restart Engineering dude, it is not a solution.
    – SuB
    Sep 20 '13 at 18:45
11

Those counters are kept by the kernel, so your answer depends on how your network card driver is built. Two possible choices:

  1. Kernel module
  2. Inside the kernel

If it is second, you can not reset counters without restarting the operating system. If it is first, you can do it by unloading the module from the kernel and then loading it back again. If your NIC card use e1000 module, use following commands:

$ ifconfig eth0 down
$ modprobe -r e1000
$ modprobe e1000
$ ifconfig eth0 up

Use ethtool to find out your NIC module:

$ ethtool -i eth0

In front of driver you see your module name:

driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
...

Use apt-get to install ethtool as follow:

$ apt-get install ethtool
4
  • modprobe -r unloads the driver from the kernel (which could leave you without a method of accessing the machine), so if you are doing this remotely I would advise just rebooting instead. Jan 9 '18 at 10:56
  • @Score_Under: A better solution for remote access is writing these command to a bash script file and then run it with nohup, i.e: nohup bash restart_counters_script.sh
    – SuB
    Jan 9 '18 at 14:25
  • Do you know how can I do this with loopback interface? Also: is possible to just unbind/bind the driver without removing the kernel module? Dec 30 '18 at 3:36
  • i had to sleep after modprobe... but after that, it works!
    – Ray Foss
    Aug 30 '20 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.