How to use the command 'ethtool' (with examples)

How to use the command 'ethtool' (with examples)

ethtool is a utility for examining and controlling network interface controllers (NIC) parameters on Linux systems. By tapping into this powerful tool, administrators and users can extract detailed information about network interfaces, modify settings to optimize performance, and troubleshoot issues effectively. With functionalities encompassing everything from displaying driver details to altering speed and duplex modes, ethtool is an essential command for managing and optimizing network interfaces.

Use case 1: Display the current settings for an interface

Code:

ethtool eth0

Motivation:

Knowing the current settings of your network interface is crucial for diagnosing network-related performance issues. Whether you are trying to troubleshoot a connectivity issue, verify the link speed, or simply document the current network configuration for auditing purposes, ethtool provides a comprehensive output that covers key parameters like supported link modes, current link speed, and duplex mode.

Explanation:

  • ethtool: This is the command invoked to inspect or modify NIC parameters.
  • eth0: This is a common designation for the first Ethernet interface on a Linux system. It represents the specific network interface for which you want to view current settings.

Example Output:

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
    Advertised link modes:  100baseT/Full
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Link partner advertised link modes: 100baseT/Full
    Link partner advertised pause frame use: No
    Link partner advertised auto-negotiation: Yes
    Speed: 100Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 1
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off

Use case 2: Display the driver information for an interface

Code:

ethtool --driver eth0

Motivation:

Understanding the specific driver managing your network interface can be essential, especially when dealing with compatibility issues or seeking support from the network hardware vendor. Sometimes, driver updates can resolve bugs or enhance performance, making detailed driver information critical for maintenance tasks.

Explanation:

  • ethtool: The command used to access NIC parameters.
  • --driver: This option specifies that the command should display driver-related information for the network interface.
  • eth0: Represents the network interface whose driver information you want to retrieve.

Example Output:

driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: N/A
expansion-rom-version: 
bus-info: 0000:00:19.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

Use case 3: Display all supported features for an interface

Code:

ethtool --show-features eth0

Motivation:

Network interface cards come with various features that can enhance performance and security, such as offloading tasks from the CPU or implementing security protocols. By listing all supported features, users can gauge the capabilities of their NIC and potentially enable features that are beneficial in their environment.

Explanation:

  • ethtool: The command line utility used for NIC examinations and adjustments.
  • --show-features: This parameter instructs ethtool to list all features supported by the network card.
  • eth0: Specifies the network interface whose features you wish to view.

Example Output:

Features for eth0:
rx-checksumming: on
tx-checksumming: on
    tx-checksum-ipv4: on
    tx-checksum-ip-generic: off [fixed]
tcp-segmentation-offload: on
    tx-tcp-segmentation: on
    tx-tcp-ecn-segmentation: off [fixed]
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off
ntuple-filters: off
receive-hashing: off
highdma: on
rx-vlan-filter: on

Use case 4: Display the network usage statistics for an interface

Code:

ethtool --statistics eth0

Motivation:

Continuous monitoring of network usage statistics is critical for bandwidth management and detecting anomalies in network traffic patterns. Whether conducting a performance analysis or checking for errors indicative of hardware issues, having access to detailed statistics helps provide insights into network interface operations.

Explanation:

  • ethtool: The main command used for interfacing with NIC parameters.
  • --statistics: This option requests network usage statistics for a given interface.
  • eth0: Indicates the network interface whose statistics you wish to view.

Example Output:

NIC statistics:
     rx_packets: 10567890
     tx_packets: 10453476
     rx_bytes: 1345678901
     tx_bytes: 1234567890
     rx_errors: 0
     tx_errors: 0
     rx_dropped: 5
     tx_dropped: 2
     multicast: 2345
     collisions: 0

Code:

ethtool --identify eth0 10

Motivation:

In environments with numerous servers and cables, pinpointing the physical location of a network interface on a server can prove challenging. By blinking the LED, administrators can quickly locate and identify the correct network port on a switch or server during hardware checks or when making changes in physical connectivity.

Explanation:

  • ethtool: The command used for interfacing with and managing NICs.
  • --identify: This flag commands the interface to blink an LED for identification purposes.
  • eth0: Refers to the network interface whose LED you want to blink.
  • 10: This is the duration in seconds for which the LED should blink.

Example Output:

Identifying eth0 by blinking its LED for 10 seconds

Code:

ethtool -s eth0 speed 1000 duplex full autoneg on

Motivation:

Adjusting the link speed and duplex settings can optimize network performance, especially in environments experiencing network congestion or connectivity issues. Properly configuring these parameters ensures that the network interface operates at optimal speed with minimal packet loss, which is crucial in high-traffic scenarios.

Explanation:

  • ethtool: The command line utility for managing network interfaces.
  • -s eth0: The option -s sets configurations; eth0 specifies the target interface.
  • speed 1000: Sets the link speed to 1000 Megabits per second, suitable for Gigabit Ethernet.
  • duplex full: Configures the duplex setting to full, allowing simultaneous send and receive operations.
  • autoneg on: Enables auto-negotiation, which allows the interface to automatically select the best link parameters.

Example Output:

Settings for eth0:
    Link detected: yes
    Speed: 1000Mb/s
    Duplex: Full
    Auto-negotiation: on

Conclusion:

ethtool is a versatile and potent tool for Linux network administrators, offering a wide array of functionalities to monitor, configure, and troubleshoot network interface cards. From examining basic interface settings to enabling advanced features or configuring specific network parameters, these use cases illustrate how ethtool can be harnessed to optimize network performance and reliability in diverse environments.

Related Posts

How to Use the Command 'seq' (with examples)

How to Use the Command 'seq' (with examples)

The seq command is a versatile tool in Unix-like operating systems for generating sequences of numbers.

Read More
How to Use the Command 'indent' (with Examples)

How to Use the Command 'indent' (with Examples)

The indent command is a utility that formats and beautifies C and C++ source code files by adjusting whitespace.

Read More
How to use the command 'zdiff' (with examples)

How to use the command 'zdiff' (with examples)

zdiff is a powerful command-line utility used to compare the contents of gzip compressed files.

Read More