When using a Linux system, network card drift may occur after installing specific network card drivers or related programs.
Possible representations are:
After installing a certain network card driver, the order of the network cards may be reversed. For example, the network port connected by the network cable was eth0 before, but it may be changed to eth1 or other names after the driver is installed.
(2) The name of the network card changes. This situation is not a change from eth0 to eth1, but a very strange change. For example, eth0 cannot be found, and there is an additional network card named __tmp3183921382193__
This situation is indeed annoying. Because some people may need to use the ifconfig | grep eth command to obtain information for development work. If the network card name is confusing, there will definitely be errors in the program.
(3) The order of the optical port network card and the electrical port network card is out of order, or they overlap.
In short, our goal is to be able to specify the name of a certain network card as the physical device we want. Here’s how to do it:
To use a network card, you first need to know which name corresponds to which physical device. The method is as follows: pull a network cable from the switch and connect it to the network card one by one from top to bottom. Note that you can only connect one network card at a time. Then use the ethtool command to check whether the network cable is connected, such as
[root@bunian ~]# ethtool eth0 Settings for eth0: Supported ports: [ MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes:10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 2 Transceiver: external Auto-negotiation: on Supports Wake-on: g Wake-on: d Link detected: yes
I saw that the status of eth0 is connected to the network cable. If Linked detected:no, it means that the network cable is not connected.
In this way, distinguish the name of which device and mark it well.
ifconfig -a can see all network devices. Get the MAC address of each device via ifconfig -a | grep HWaddr.
for example:
[root@bunian ~]# ifconfig-a | grep HWaddr eth0Link encap:EthernetHWaddr 00:30:48:7F:B5:CA eth1Link encap:EthernetHWaddr 00:30:48:7F:B5:CB eth2Link encap:EthernetHWaddr 00:04:23:A6:81:E0 eth3Link encap:EthernetHWaddr 00:04:23:A6:81:E1
Got the MAC address of each network card.
We all know that for RedHat systems, the configuration file of the network card is:
Stored in/etc/sysconfig/network-scripts/ifcfg-ethX, X=0, 1, 2. . .
for example:
[root@bunian]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 # nVidia Corporation MCP55 Ethernet DEVICE=eth0 ONBOOT=yes HWADDR=00:30:48:7f:b5:ca TYPE=Ethernet NETMASK=255.255.255.0 IPADDR=192.168.42.231 GATEWAY=192.168.42.1 BOOTPROTO=static #NAMESERVER=202.106.0.20
This file is the configuration file for initializing the network card. For example, if we want to specify the device name of the network card MAC address MAC1 as ethn, then modify the file
/etc/sysconfig/network-scripts/ifcfg-ethn
Add the configuration information of MAC address binding and name inside
DEVICE=ethn
HWADDR=MAC1 (for example 00:30:48:7f:b5:ca)
Other configuration information is not affected. After binding all network cards, reboot the system and it should be fine.
Another thing to note is the file that drives the corresponding relationship:
/etc/modprobe.conf
To modify in this file, make sure that a certain device uses the driver corresponding to it, such as:
cat /etc/modprobe.conf alias eth0 forcedeth alias eth1 forcedeth alias scsi_hostadapter aic79xx alias scsi_hostadapter1 sata_nv alias scsi_hostadapter2 usb-storage alias eth2 e1000 alias eth3 e1000
Explain that eth0 and eth1 use the forcedeth driver, and eth2 and eth3 use the e1000 driver.
After the server replaces the network card, the MAC address will change. At this time, after starting the Linux system, the original eth0 and eth1 are no longer the configuration files of the current network card, and a prompt will be displayed that device eth0 does not seem to be present.
Solution:
Just delete /etc/udev/rules.d/70-persistent-net.rules and then restart the machine, because this file saves the identification information of the network card at the bottom of the system, including the correspondence between ethX and MAC. Delete and Restart and let the operating system re-recognize the existing network card and then it will return to normal.
In addition, if the original eth0 and eth1 configuration files have HWADDR fields, they also need to be deleted.
The above is the detailed content of Binding method of linux network card identification sequence. For more information, please follow other related articles on the PHP Chinese website!