Introduction
A few days ago, when testing the network speed on zimaboard's intranet, I found that the network speed was stuck at 100Mbps. After multiple debugging attempts, I discovered that it was because the network card was configured as 100M full duplex for some unknown reason. So, I will record how I configured the network card in Linux below. In the Linux operating system, the network card is one of the key components that connects the computer to the network. The speed and working mode of the network card directly affect the speed and stability of the network connection. This article will introduce how to view the network card configuration information in Linux and how to switch the working mode of the network card.
Some Basic Knowledge
Working Principle of Network Card
The network card is an interface device between the computer and the network. It is responsible for converting computer data into network data and converting network data into data that the computer can process. The working principle of the network card is to connect the network cable to the switch, transmitting data packets from one network node to another.
Network Card Speed
The speed of the network card refers to the amount of data that the network card can transmit per second, usually expressed in Mbps (megabits per second). In network communication, the faster the speed of the network card, the faster the data transmission speed. Gigabit Ethernet is a commonly used high-speed network interface, with a speed of 1000Mbps.
Full Duplex and Half Duplex
Full Duplex means that both parties can send and receive data at the same time. Half Duplex means that both parties cannot send and receive data at the same time, they can only send or receive first. Full Duplex communication is more efficient and stable than Half Duplex communication.
Viewing Network Card Configuration Information
To view the network card configuration information in the Linux system, you can use the ifconfig command. This command can list all the network interface devices in the system and their configuration information. Enter the following command in the terminal:
ifconfig
Output Example:
...
Switching Network Card Working Mode
In the Linux system, you can use the ethtool command to configure the working mode of the network card. ethtool is a tool for configuring network interface devices. It can view and modify the driver and hardware settings of network interface devices.
Step 1: Install ethtool
If the ethtool tool is not installed in the system, you can install it with the following command:
#centos
sudo yum install ethtool
#debian,ubuntu
sudo apt install ethtool
Step 2: View Network Card Working Mode
To view the current working mode of the network card, you can use the following command:
ethtool
#e.g. ethtool eth0
Where eth0 is the name of the network card to be viewed. This command will output the configuration information of the network card, including the current working mode.
Step 3: Modify Network Card Working Mode
To modify the working mode of the network card, you can use the following command:
ethtool -s eth0 speed 1000 duplex full
Where eth0 is the name of the network card to be modified, speed is the speed of the network card, and duplex is the working mode of the network card. Here, the speed of the network card is set to 1000Mbps, and the working mode is set to full duplex mode. After completion, you can use the ethtool command to view the configuration information of the network card again to confirm that the settings have taken effect.
Supplement: Detailed Usage of ethtool
View Network Card Information
To view the information of a network interface device, you can use the following command:
ethtool eth0
Where eth0 is the name of the network interface device to be viewed. This command will output detailed information about the network interface device, including driver information, speed, working mode, etc.
Modify Network Card Speed
To modify the speed of a network interface device, you can use the following command:
ethtool -s eth0 speed 1000
Where eth0 is the name of the network interface device to be modified, and speed is the speed value to be set. Here, the speed of the network card is set to 1000Mbps.
Modify Network Card Working Mode
To modify the working mode of a network interface device, you can use the following command:
ethtool -s eth0 duplex full
Where eth0 is the name of the network interface device to be modified, and duplex is the working mode to be set. Here, the working mode of the network card is set to full duplex mode.
Turn On or Off Auto-Negotiation
Auto-Negotiation is a technology that automatically negotiates the speed and duplex mode of a device. To turn on or off Auto-Negotiation, you can use the following command:
ethtool -s eth0 autoneg on/off
Where eth0 is the name of the network interface device to be modified, and autoneg is the Auto-Negotiation status to be set. Here, Auto-Negotiation is set to the on state.
View Network Card Statistics
To view the statistics of a network interface device, you can use the following command:
ethtool -S eth0
Where eth0 is the name of the network interface device to be viewed. This command will output the statistics of the network interface device, including the number of received and transmitted packets, error counts, etc.
Summary
This article introduces how to view the network card configuration information in Linux and provides detailed instructions on how to switch the working mode of the network card. By using the ethtool command, it is easy to switch the working mode of the network card.