Information and Statistics Commands

This document collects methods for viewing layer 2 information from Linux network interfaces, including collision statistics, MAC addresses, and other hardware-level details.

Using the ip Command

The ip command can show basic layer 2 information:

bash

# Show link layer information for all interfaces
ip link show

# Show link layer information for a specific interface
ip link show dev eth0

This provides information such as:

  • MAC address
  • Interface state (UP/DOWN)
  • MTU (Maximum Transmission Unit)
  • Link mode (e.g., DORMANT)
  • Link type (e.g., Ethernet)

Using ethtool for Detailed Statistics

The ethtool command is the most powerful tool for viewing detailed layer 2 information and statistics:

bash

# Install ethtool if not already installed
# sudo apt install ethtool # Debian/Ubuntu
# sudo yum install ethtool # RHEL/CentOS

# Basic interface information
ethtool eth0

# Show driver information
ethtool -i eth0

# Show detailed interface statistics including collisions
ethtool -S eth0

# Show link status
ethtool -l eth0

# Show transceiver/port settings
ethtool -m eth0

# Show pause parameters
ethtool -a eth0

# Show ring buffer parameters
ethtool -g eth0

Specific Layer 2 Statistics from ethtool

The ethtool -S command provides detailed statistics including:

bash

# Example output for ethtool -S eth0
rx_packets # Total received packets
rx_bytes # Total received bytes
rx_errors # Bad packets received
rx_dropped # Packets dropped
rx_fifo_errors # FIFO overrun errors
rx_frame_errors # Frame alignment errors
rx_compressed # Compressed packets
rx_multicast # Multicast packets received

tx_packets # Total transmitted packets
tx_bytes # Total transmitted bytes
tx_errors # Packet transmit problems
tx_dropped # Packets dropped
tx_fifo_errors # FIFO overrun errors
tx_collisions # Number of collisions detected
tx_carrier_errors # Carrier losses
tx_compressed # Compressed packets transmitted

# For more detailed statistics with specific groups
ethtool -S eth0 --groups eth-phy eth-mac eth-ctrl rmon

Using ifconfig (Legacy Method)

The ifconfig command also provides some layer 2 information:

bash

# Show interface information including some layer 2 details
ifconfig eth0

# Example output includes:
# - MAC address (HWaddr)
# - MTU
# - RX/TX packets
# - RX/TX errors
# - RX/TX dropped
# - Collisions
# - Carrier errors

Using /proc and /sys Filesystem

Direct access to kernel statistics through the filesystem:

bash

# Interface statistics in /proc
cat /proc/net/dev

# Example output format:
# Interface | Receive | Transmit
# | bytes packets errs drop fifo frame compressed multicast | bytes packets errs drop fifo colls carrier compressed

# More detailed information in /sys filesystem
ls -l /sys/class/net/eth0/
cat /sys/class/net/eth0/address # MAC address
cat /sys/class/net/eth0/statistics/ # Directory with detailed statistics
cat /sys/class/net/eth0/statistics/collisions # Collision count
cat /sys/class/net/eth0/statistics/rx_errors # Receive errors
cat /sys/class/net/eth0/statistics/tx_errors # Transmit errors

Using netstat for Interface Statistics

bash

# Show interface statistics
netstat -i

# Example output includes:
# - MTU
# - RX-OK/RX-ERR
# - TX-OK/TX-ERR
# - Collisions (Collisions detected during transmission)
# - Flags

# More detailed statistics
netstat -s

Using ip -s for Statistics

bash

# Show statistics for all interfaces
ip -s link

# Show statistics for a specific interface
ip -s link show dev eth0

# Show more detailed statistics (repeat -s for more detail)
ip -s -s link show dev eth0

Using mii-tool for Media-Independent Interface Information

bash

# Install mii-tool if not already installed
# sudo apt install net-tools # Debian/Ubuntu
# sudo yum install net-tools # RHEL/CentOS

# Check MII status of interfaces
mii-tool eth0

# Verbose output
mii-tool -v eth0

Using tcpdump for Real-time Layer 2 Analysis

bash

# Capture and display packets at layer 2
tcpdump -e -i eth0

# The -e flag displays the link-level header (MAC addresses)

Understanding Collision Statistics

In modern networks, collisions are rare due to the prevalence of switched networks rather than shared media. However, they can still occur in half-duplex environments or indicate other issues:

  1. Collisions: Number of collisions detected during packet transmission
  2. Late Collisions: Collisions that occur after the standard collision window (typically after 512 bit times) - often indicates duplex mismatch
  3. Excessive Collisions: Packets dropped after multiple collision retry attempts

High collision counts may indicate:

  • Duplex mismatch (one side half-duplex, other full-duplex)
  • Overloaded network segment
  • Faulty NIC or cable
  • Hub-based network (rather than switch-based)

Checking Duplex Settings

Duplex mismatches are a common cause of performance issues and can lead to collisions:

bash

# Check current speed and duplex settings
ethtool eth0

# Set duplex mode (if needed)
ethtool -s eth0 speed 100 duplex full
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>