Ethtool is a networking utility on Linux. It is used to view and change the ethernet device parameters. In this article you will learn how to use ethtool command on Linux.
The configuration of your Ethernet card allows your computer to communicate effectively over the network. Ethtool provides many information about Ethernet devices connected to your Linux system. You can change ethernet card parameters as required, including auto-negotiation, Speed, Duplex and Wake-on LAN.
The following information will help you understand how Ethernet card works.
- Auto-Negotiation: It is a mechanism that allows a device to automatically choose the best network speed and mode of operation.
- Speed: By default it uses maximum speed and you can change it according to your need.
- Half Duplex: Allows a device to either send or receive packets at a time.
- Full Duplex: Allows a device to send and receive packets simultaneously.
- Wake-on-LAN (WoL): Industry standard protocol that allows a computer to be turned on or awakened by a network message.
- Link detection: Shows the status of the network interface card. If it shows “no” then try restarting the interface. If the link detection still says “no”, check if there are any issues with the cables connected between the switch and the system.
How to check the available Network Interface Card (NIC) on Linux
Firstly you’ll need to know the name of your network interface card. To find the name of your network interface card, run the following command from the command terminal:
ifconfig
enp5s0: flags=4163 mtu 1500
inet 192.168.0.101 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::65f2:72ae:2878:8a76 prefixlen 64 scopeid 0x20
inet6 fd37:45bb:20bd::45e prefixlen 128 scopeid 0x0
inet6 fd37:45bb:20bd:0:da60:e2eb:96ad:ec26 prefixlen 64 scopeid 0x0
ether 2c:5a:3f:c4:02:8b txqueuelen 1000 (Ethernet)
RX packets 1006202 bytes 940298098 (896.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 550734 bytes 123076237 (117.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfc200000-fc2fffff
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 5546564 bytes 324011516 (309.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5546564 bytes 324011516 (309.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
In the above example, the name of the device is enp5s0.
How to check Network Interface Card (NIC) information on Linux with ethtool
Once you have the Ethernet interface name, you can easily check the details of it using the ethtool command.
When you execute ethtool command with a device name, it displays ethernet card properties such as speed, wake on, duplex and the link detection status.
sudo ethtool enp5s0
Settings for enp5s0:
Supported ports: [ ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
2500baseT/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
2500baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: on
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
MDI-X: off (auto)
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
How to check ethernet card driver and firmware version on Linux with ethtool
You can check driver version, firmware version, and bus details using the ethtool command with the “-i” option as shown below.
sudo ethtool -i enp5s0
driver: igc
version: 5.9.14-arch1-1
firmware-version:
expansion-rom-version:
bus-info: 0000:05:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes
How to change ethernet card settings on Linux with ethtool
The “-s” option can be used to change the current settings by defining the values for speed, duplex, and autoneg in the following format:
sudo ethtool -s [device_name] speed [10/100/1000] duplex [half/full] autoneg [on/off]
For example, to set the speed at 100Mb/s, the duplex mode to ‘full’ and the auto-negotiation to ‘on’ the command would be:
sudo ethtool -s enp5s0 speed 100 duplex full autoneg on
In addition, you can change each option individually:
sudo ethtool -s enp5s0 speed 100
sudo ethtool -s enp5s0 duplex full
sudo ethtool -s enp5s0 autoneg on
Note: Once you change the speed when the adapter is online, it automatically goes offline, and you need to bring it back online using ifup command.
sudo ifup enp5s0
Please note that if you’ve changed any ethernet card parameters using the ethtool, it will all disappear after the next reboot.
How to persist ethtool settings across reboot
However after a system restarts the changes you made with ethtool will be reverted by default.
To make custom settings permanent, you need to update your value in the network configuration file. Depending on your Linux distribution you may need to update this value to the correct file.
For RedHat/CentOS based systems modify the /etc/sysconfig/network-scripts/ifcfg-eth-id file and include a line as shown below:
sudo vi /etc/sysconfig/network-scripts/ifcfg-enp5s0
ETHTOOL_OPTS="speed 100 duplex full autoneg on"
For Debian/Ubuntu based systems you have to modify /etc/network/interfaces file and add your changes as shown below:
sudo vi /etc/network/interfaces
post-up ethtool -s enp5s0 speed 100 duplex full autoneg on
Conclusion
You have figured out that this is just a basic introduction to ethtool, because it provides many other options not explained above. Combined with other such tools this can become one deadly tool in a sysadmin’s bag of tricks.