Unveiling the Power of `ethtool`: Your Gateway to Network Driver and Hardware Control
In the realm of networking, having precise control over network drivers and hardware is crucial. Whether you're a system administrator troubleshooting connectivity issues, a network engineer optimizing performance, or a developer working on network-related applications, understanding the tools at your disposal is essential. One such powerful tool is ethtool. This blog post will delve deep into ethtool, exploring its functionality, common use cases, best practices, and example usage.
Table of Contents#
- What is
ethtool? - Installation
- Basic Usage
- Advanced Usage
- Best Practices
- Common Pitfalls and Troubleshooting
- References
What is ethtool?#
ethtool is a command-line utility in Linux systems that allows users to query and configure network interface controllers (NICs) and their associated drivers. It provides a wide range of capabilities, from retrieving basic information about a network interface (such as its speed, duplex mode, and driver version) to adjusting advanced settings like offloading features (e.g., TCP segmentation offloading, large receive offloading) and even performing hardware diagnostics.
Installation#
On most Linux distributions, ethtool is already installed by default. However, if it's missing on your system, you can install it using the package manager. For example:
- Debian/Ubuntu:
sudo apt-get install ethtool- CentOS/RHEL:
sudo yum install ethtoolBasic Usage#
Querying Network Interface Information#
One of the most common uses of ethtool is to gather information about a network interface. Let's say you want to check details about the interface eth0.
Example:
ethtool eth0This will display output like:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric Receive-only
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Supports Wake-on: pumbg
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
Here, you can see details like the supported link modes, current speed (in this case, 1000Mb/s), duplex mode (Full), and whether auto-negotiation is enabled.
Changing Link Settings#
Suppose you want to force the interface eth0 to operate at a specific speed and duplex mode (let's say 100Mb/s full duplex).
Example:
sudo ethtool -s eth0 speed 100 duplex full autoneg offExplanation:
-s: This option is used to set the parameters.speed 100: Sets the speed to 100Mb/s.duplex full: Sets the duplex mode to full.autoneg off: Disables auto-negotiation.
Configuring Offloading Features#
Offloading features offload certain network processing tasks from the CPU to the NIC hardware. For example, to enable TCP segmentation offloading (TSO) on eth0:
Example:
sudo ethtool -K eth0 tso onExplanation:
-K: This option is used to modify the offloading features.tso on: Enables TCP segmentation offloading.
You can also check the current status of offloading features:
ethtool -k eth0Which will show output like:
Features for eth0:
rx-checksumming: on
tx-checksumming: on
tx-checksum-ipv4: on (fixed)
tx-checksum-ip-generic: off
tx-checksum-ipv6: on (fixed)
tx-checksum-fcoe-crc: off
tx-checksum-sctp: off
scatter-gather: on
tx-scatter-gather: on
tx-scatter-gather-fraglist: off
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp-ecn-segmentation: off
tx-tcp-mangleid-segmentation: off
tx-tcp6-segmentation: on
udp-fragmentation-offload: off
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off
receive-hashing: on
highdma: on
rx-vlan-filter: off
vlan-challenged: off
tx-lockless: off
netns-local: off
tx-gso-robust: off
tx-fcoe-segmentation: off
tx-gre-segmentation: off
tx-gre-csum-segmentation: off
tx-ipxip4-segmentation: off
tx-ipxip6-segmentation: off
tx-udp_tnl-segmentation: off
tx-udp_tnl-csum-segmentation: off
tx-gso-partial: off
tx-sctp-segmentation: off
tx-esp-segmentation: off
tx-udp-segmentation: off
fcoe-mtu: off
tx-nocache-copy: off
loopback: off
rx-fcs: off
rx-all: off
tx-vlan-stag-hw-insert: off
rx-vlan-stag-hw-parse: off
rx-vlan-stag-filter: off
l2-fwd-offload: off
hw-tc-offload: off
esp-hw-offload: off
esp-tx-csum-hw-offload: off
rx-udp_tunnel-port-offload: off
tls-hw-tx-offload: off
tls-hw-rx-offload: off
Advanced Usage#
Monitoring Network Statistics#
ethtool can be used to monitor network statistics. For example, to get the statistics related to the number of packets received, transmitted, errors, etc., on eth0:
Example:
ethtool -S eth0This will display a long list of statistics like:
NIC statistics:
rx_packets: 123456
tx_packets: 789012
rx_bytes: 123456789
tx_bytes: 987654321
rx_errors: 0
tx_errors: 0
rx_dropped: 0
tx_dropped: 0
collisions: 0
rx_length_errors: 0
rx_over_errors: 0
rx_crc_errors: 0
rx_frame_errors: 0
rx_fifo_errors: 0
rx_missed_errors: 0
tx_aborted_errors: 0
tx_carrier_errors: 0
tx_fifo_errors: 0
tx_heartbeat_errors: 0
tx_window_errors: 0
rx_compressed: 0
tx_compressed: 0
Debugging and Diagnostics#
Some NICs support hardware diagnostics. For instance, to perform a basic link test on eth0 (if supported by the NIC):
Example:
sudo ethtool -t eth0This may output something like:
Testing ...
1. Link test: OK
Best Practices#
- Backup and Test: Before making any significant changes to network interface settings (especially in a production environment), always backup the current configuration (you can use
ethtoolcommands to record the current settings). Also, test the changes in a non-production or isolated environment if possible. - Understand the NIC Capabilities: Different NICs support different features. Check the documentation of your specific NIC to know which offloading features, link settings, etc., are truly supported.
- Regular Monitoring: Use the statistics querying feature (
ethtool -S) regularly to keep an eye on network performance. Sudden spikes in error counts or drops in packet counts can indicate issues.
Common Pitfalls and Troubleshooting#
- Permissions: Many
ethtooloperations (like changing settings) require root privileges. If you get a "permission denied" error, try usingsudo. - NIC Compatibility: Some older or less common NICs may not support all the features that
ethtooltries to configure. If a setting change doesn't seem to take effect or causes issues (like a loss of network connectivity), check the NIC's documentation and revert the change. - Auto-negotiation Conflicts: If you force specific link settings (like speed and duplex) and auto-negotiation is still enabled (even if you thought you disabled it), there can be conflicts. Double-check the
autonegsetting.
References#
- The official
ethtoolman page - Linux networking documentation resources (e.g., the Linux Kernel documentation for network drivers if you want to dig deeper into how
ethtoolinteracts with them).
By mastering ethtool, you gain a powerful tool in your networking arsenal to manage, optimize, and troubleshoot your network interfaces effectively. Whether it's fine-tuning performance or diagnosing issues, ethtool is a go-to utility for any Linux user dealing with network drivers and hardware.