The ethtool command is used to display/change Ethernet adapter settings. You can change network card speed, auto-negotiation, wake on LAN setting, duplex mode using this tool in Linux.
In this article, I will show you some ethtool command examples that help you to troubleshoot ethernet card issues.
1) Display Ethernet Interface Details
The ethtool command retrieves the status of the Ethernet interface. The output displays properties like speed, duplex, status and wake on of the etho interface.
Given below is an example:
# ethtool eth0
Settings for eth0:
Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
Advertised auto-negotiation: Yes
Port: Twisted Pair
Supports Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes
There are three types of duplexes:
Full Duplex: Used when the Ethernet is connected to the switch. Allows two- way transfers, that is, sending and receiving of packets simultaneously.
Half Duplex: Used when the Ethernet is in connection with the hub. Allows only one- way transfers, that is, either sending or receiving of packets.
Auto negotiation: On the basis of the network connection, the Ethernet interface decides whether to use full or half duplex.
2) ETHTOOL_OPTS Variable
The Ethtool command settings can be set permanently with the Ethtool_opt variable. Let us have a look at the example given below:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
ETHTOOL_OPTS="speed 50 duplex full autoneg off"
You can test the above setting with ifup and ifdown commands.
3) Display Statistics
The Ethernet driver settings and auto-negotiation can be checked with the following commands:
# ethtool -i eth0
[[email protected] ~]# ethtool –a eth0
Pause parameters for eth0:
The '–p option' of Ethtool command helps to identify the specific device from multiple devices.
# ethtool –p eth0
Having the statistics of network card is very useful in troubleshooting of network issues.
# ethtool –S eth0
The output above shows the details about the transferred and received packets.
4) Enable flow control
Flow control in full duplex can be enabled by 'PAUSE' parameter in the latest MAC and GMAC embedded devices.
Here is the solution:
# ethtool -A eth0 [autoneg on|off] [rx on|off] [tx on|off]
Offload parameters details can be obtained as follows:
# ethtool –k eth0
However, any changes made in the Ethernet parameter settings will disappear at the time of the next boot. In order to have them intact in the next boot, you have to make these changes permanent by adding the command to /etc/rc.local
# cat /etc/rc.local
ethtool -s eth0 speed 100 duplex full autoneg on 1>/dev/null 2>/dev/null
ethtool -s eth1 speed 100 duplex full autoneg on 1>/dev/null 2>/dev/null
5) Set Duplex Mode
Below example shows how to set speed or duplex mode using ethtool command is as follows:
# ethtool -s eth0 speed 100 duplex full
# ethtool -s eth0 speed 10 duplex half