Solution to the problem that network card cannot be recognized when adding network card to CentOS in virtual machine

Time:2020-10-25

When we do the experiment today, we need to add a new network card for the virtual machine, but the system can’t recognize it. All kinds of Baidu, Google and all kinds of restart are not successful
I thought it would be recognized by adding a new piece of system, but it is not
Conclusion: to rewrite the new network card configuration file and modify hwaddr, otherwise LSB error will be reported
Here’s my solution:
1. After the new network card is added, ifconfig is executed and the system does not recognize it

Copy code

The code is as follows:

#ifconfig

201633111711321.png (531×283)

2. Get the real MAC of the new network card

Copy code

The code is as follows:

#ip addr

201633111736253.png (573×236)

3. Copy eth0 to eth1 and modify the configuration file

Copy code

The code is as follows:

#cd /etc/sysconfig/network-scripts
#cp ifcfg-eth0 ifcfg-eth1
#vim ifcfg-eth1

The contents to be modified are as follows:
Hwadd is obtained through IP addr
UUID I didn’t find UUID. I can comment it out
Name is changed to the current network card name eth1
Change device to the current network card name eth1
IPADDR, gateway, etc
Save exit
4. Restart the network card and you can see that it has been obtained

Copy code

The code is as follows:

#systemctl restart network
#ifconfig

201633111753188.png (484×420)

PS: the network card name in centos7 is changed to eth0
Because I often switch between centos6 and centos7 systems, I think the network card name of centos7 is too long and inconvenient, so I want to make it the same as 6
You want to change the name of the network card to eth0 and eth1 the same as 6, and perform the following operations
1.

Copy code

The code is as follows:

#cd /etc/sysconfig

2. Add the following sentence in the longest line

Copy code

The code is as follows:

#vim grub
net.ifnames=0 biosdevname=0

201633111842569.png (844×135)

3.

Copy code

The code is as follows:

#grub2-mkconfig -o /boot/grub2/grub.cfg

4. Rename the original network card name

Copy code

The code is as follows:

#cd /etc/sysconfig/network-scripts
#mv ifcfg-enoXXXXXXXX ifcfg-eth0

5. Modify the name in ifcfg-eth0 and the name of device to eth0

Copy code

The code is as follows:

NAME=eth0
DEVICE=eth0

6. Reboot, and check to find that it has become the eth0 we want
201633111857081.png (568×155)