Introduction
The configuration of your Ethernet Card defines how effectively your servers communicate.
It is necessary to understand how Auto-Negotiation, Speed, and Duplex settings affect the transfer of data to maintain network connectivity with minimal effort.
This article will show you how to change Speed, Duplex, and Auto-Negotiation settings in Linux with ethtool commands.
Prerequisites
- Command-line/terminal window
- A user account with root or sudo privileges
- The Ethtool configuration tool installed
Half Duplex, Full Duplex, and Auto-Negotiation
Half-duplex mode allows a device to either send or receive packets in turn. A device set to this mode cannot perform both actions at the same time.
When a device’s mode is at full-duplex, it can also send and receive packets simultaneously.
Auto-Negotiation is a mechanism by which a device automatically chooses the best performing transmission mode based on its counterparts’ characteristics. It is recommended to keep Auto-Negotiation enabled as it allows devices to choose the most efficient means for the transfer of data.
What is a Duplex Mismatch?
When a device, with enabled auto-negotiation, connects to a device that is not using this signaling method, the process does not work. The end of the connection with an active auto-negotiation is still able to detect the speed of the other end, but cannot correctly detect the duplex mode. As a rule, the auto-negotiating end of the connection is going to use half-duplex while the other end might be at full-duplex. This situation is considered a duplex mismatch.
A duplex mismatch does not stop communication completely. Single packets and small amounts of data do not cause immediate issues. However, when a large amount of data is sent from either end, the speed drops significantly. The connection is working, but the performance is reduced as the data transfer rate is asymmetrical and might lead to packet loss.
How to Use Ethtool Command to Configure NIC Settings
Ethtool is a Network Interface Card configuration command that allows you to retrieve information and change your NIC settings. These settings include Speed, Duplex, Auto-Negotiation, and many other parameters.
To proceed, 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
The command works with both Linux Centos 7 and Ubuntu. The output provides the name of the device interface card. To learn more about this command, read our guide How to Install and Use ifconfig.
In the above example, the name of the device is enp0s3.
Now that you have determined the name of the device, check the current Speed, Auto-Negotiation, and Duplex mode settings with the command: ethtool devicename
.
In our specific example the command is:
ethtool enp0s3
The output shows that the current speed is 1000Mb/s, that the Duplex is at ‘Full,’ and that Auto-Negotiation is turned on.
Ethtool Command to Change Ethernet Adapter Settings
The ethtool -s
command 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 1000Mb/s, the duplex mode to ‘full’ and the auto-negotiation to ‘on’ the command would be:
sudo ethtool -s enp0s3 speed 1000 duplex full autoneg on
The ethtool [device_name]
command is necessary to confirm that the changes have been applied.
Ethtool_opt Variable to Permanently Set Ethtool Command Settings
Changes made with Ethtool are by default reverted after a system is re-booted.
To apply custom settings each time a system boots edit the file for the device interface:
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Add the desired values as a line at the end of the file using the following syntax:
ETHTOOL_OPTS="speed [100|1000|10000] duplex [half|full] autoneg [on|off]”
For example:
ETHTOOL_OPTS="speed 1000 duplex full autoneg on"
Save the changes and exit the file.
Now the changes are applied after every reboot and are permanent unless the file is altered again.
Conclusion
By following this tutorial, you have successfully changed the settings on your Network Interface Card with ethtool commands. You have also gained a better understanding of how Auto-Negotiation and Duplex modes affect server performance.
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/226132.html