Every Linux user is probably familiar with the ifconfig command. This allows us to see the current network settings on a system and to make various changes to the network interfaces (change IP, bring up, down, etc.). A typical run of ifconfig (or ifconfig -a) without any parameters will show the status of all the network interfaces, while using a network interface name (like ifconfig eth0) will output the status of only that interface.
Let’s see how a sample output looks like:
ifconfig eth0
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4233700943 errors:2 dropped:0 overruns:3 frame:5
TX packets:1917219659 errors:1 dropped:0 overruns:0 carrier:348
collisions:5753 txqueuelen:3000
RX bytes:1467520026 (1.3 GiB) TX bytes:2299240337 (2.1 GiB)As we can see here ifconfig is keeping a couple of counters (RX/TX packets, RX/TX bytes, errors, dropped, overruns, frame, carrier collisions). We can quickly spot if there is a problem by just looking at the ifconfig counters. It is not the scope of this post how to solve these issues, but let’s consider that the problem is solved and then we normally don’t want to see the errors there anymore. Of course if there are new errors that show the same problem or a new one that would be ok to see them. So the normal thought is how to clear those counters and start fresh. How to reset them? If someone has tried to do this before, they might tell us that restarting the network interface will not help. This would have been the most logical choice, but how can we do this without rebooting the system?
The idea is that those counters are kept by the kernel (more exactly by the network card driver). By the way we can look at the same counters directly on the proc system using:
cat /proc/net/devConsidering this, we have 2 possible choices: the network card driver is build either as a kernel module or build-in statically inside the kernel. These relate to our issue like this:
modprobe -r e100; modprobe e100; ifup eth0or something similar to bring the interface back up (depending on your particular Linux distribution the script to bring up the network interface might be different).
Note: this will bring down the network interface, and if you are doing this over a ssh connection, use extra care (like maybe create a small script, add some extra measures to ensure you will not lock yourself out of the system).
By the way a quick way to find out what particular driver is using a network interface is to use ethtool (a very powerfool tool that has many great usages):
ethtool -i eth0
driver: e100
version: 3.4.14-k4-NAPI
firmware-version: N/A
bus-info: 0000:01:07.0I hope that you found this post useful and please feel free to use the comment box bellow to let me know if you have any additions/corrections to this.
转自http://www.ducea.com/2006/09/08/resetting-ifconfig-counters/
[@more@]来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12759501/viewspace-1042439/ ,如需转载,请注明出处,否则将追究法律责任。