When troubleshooting network issues on Linux systems, the ifconfig
or ip -s link
commands display valuable interface statistics including:
RX errors: [error_count]
TX errors: [error_count]
collisions: [count]
These counters persist until manually cleared or the system reboots. In cases like duplex mismatches where you've resolved the underlying issue but want to monitor fresh statistics, clearing these counters becomes necessary.
1. Using iproute2 (Recommended)
The modern approach using the ip
command:
sudo ip -s -s link set eth0 down
sudo ip -s -s link set eth0 up
This sequence forces the network driver to reinitialize, resetting all counters. The double -s
flag ensures statistics are displayed before and after the operation.
2. Traditional ifconfig Method
For older systems still using ifconfig:
sudo ifconfig eth0 down
sudo ifconfig eth0 up
3. Driver-Specific Solutions
Some network drivers support direct counter reset through sysfs:
# For Intel NICs:
echo 1 | sudo tee /sys/class/net/eth0/device/reset
# For Broadcom:
echo 1 | sudo tee /sys/class/net/eth0/device/flush
After clearing counters, verify with:
ip -s link show eth0
# or
ifconfig eth0
All error counters should now show zero (except packet counts which may increment immediately).
For regular monitoring, create a reset script:
#!/bin/bash
INTERFACE="eth0"
ip -s -s link set $INTERFACE down
ip -s -s link set $INTERFACE up
logger "Reset network counters for $INTERFACE"
Set as cron job if needed.
- Interface reset causes brief network disruption (~1-2 seconds)
- Some virtual interfaces may not support counter reset
- Certain NIC models maintain separate hardware counters
html
When diagnosing network issues on Linux systems, interface statistics provide crucial debugging information. The output from ifconfig
or ip -s link
shows counters like:
RX packets:630331763 errors:1 dropped:0 overruns:0 frame:0
TX packets:676081436 errors:1971815 dropped:0 overruns:68637 carrier:1903180
collisions:7649984
These counters persist until either the interface is reset or the system reboots. In production environments, we often need to clear these counters without system disruption.
1. Using iproute2 (Modern Approach)
The ip
command from iproute2 allows counter reset:
# Reset RX counters
sudo ip -stats link set dev eth0 rx 0
# Reset TX counters
sudo ip -stats link set dev eth0 tx 0
# Verify cleared stats
ip -s link show eth0
2. Traditional ifconfig Method
For older systems using net-tools:
# Bring interface down and up
sudo ifconfig eth0 down
sudo ifconfig eth0 up
# Verify
ifconfig eth0
3. Ethtool Alternative
Some NIC drivers support statistics reset via ethtool:
# Check if your driver supports stats reset
ethtool --show-priv-flags eth0
# Reset if supported
sudo ethtool --reset-stats eth0
For monitoring systems where regular resets are needed:
#!/bin/bash
# Daily counter reset cron job
INTERFACE=eth0
ip -stats link set dev $INTERFACE rx 0
ip -stats link set dev $INTERFACE tx 0
logger "Reset network counters for $INTERFACE"
- Root privileges are required for all methods
- Some virtual interfaces may not support counter reset
- Reset operations may briefly interrupt traffic
- Always verify with
ip -s link
after reset