Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify the name of network card under Linux

2025-04-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to modify the name of the network card under Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

I. Environment

VirtualBox + CentOS6.5

Second, the question

Sometimes you encounter this situation when configuring the network after you clone the server, or when maintaining a server that someone else has built. As shown in the following figure:

That is, in the interface configuration file ifcfg-eth0, the information of the network card eth2 is configured.

This inconsistency may cause some trouble to obsessive-compulsive disorder, and sometimes what we want more is: in the ifcfg-eth0 file, the configuration should be the information of the network card eth0, while the network card eth2 should be configured in ifcfg-eth2.

III. Solutions

There are roughly two ways to solve the above problems:

1) modify the file name of the interface configuration file from ifcfg-eth0 to ifcfg-eth2

2) modify the name of the network card eth2 to eth0.

Method 1:

The actual measurement of this method is feasible, as shown in the following figure, you can restart the network directly after modification.

Method 2:

The intuitive feeling of this method is to directly change the name of the Nic from eth2 to eth0 in the ifcfg-eth0 configuration file, but if it is changed in this way, there will be an error in restarting the network, that is, the device eth0 does not exist. As shown in the following figure, the solution to this problem is referred to "L08-Linux solving Device eth0 does not seem to be present,delaying initialization problem".

So it can't be changed simply and rudely, because, as queried by the ifconfig-a command in the following figure, the network card identified by the server is still eth2, not eth0.

Note: keep in mind that the mac address here is 08DV 00Rd 27Rd 74Rd 39J02.It can be used as a basis for modification in the following implementation steps, because the IP of a server can be changed at will, but the mac address is unique.

In order to solve this problem, we first modify the configuration in the / etc/udev/rules.d/70-persistent-net.rules file to change the name of the server's network card from eth2 to eth0, then we change the name of the network card in ifcfg-eth0, and finally restart the network.

1) modify the configuration file / etc/udev/rules.d/70-persistent-net.rules.

The original / etc/udev/rules.d/70-persistent-net.rules file is as follows:

# This file was automatically generated by the / lib/udev/write_net_rules# program, run by the persistent-net-generator.rules rules file.## You can modify it, as long as you keep each rule on a single# line, and change only the value of the NAME= key.# PCI device 0x8086:0x100e (e1000) SUBSYSTEM== "net", ACTION== "add", DRIVERS== "? *", ATTR {address} = = "08:00:27:9b:bb:3c", ATTR {type} = = "1", KERNEL== "eth*" NAME= "eth0" # PCI device 0x8086:0x100e (e1000) SUBSYSTEM== "net", ACTION== "add", DRIVERS== "? *", ATTR {address} = = "08type 0074V 3902", ATTR {type} = = "1", KERNEL== "eth*", NAME= "eth2"

The revised content is as follows:

# This file was automatically generated by the / lib/udev/write_net_rules# program, run by the persistent-net-generator.rules rules file.## You can modify it, as long as you keep each rule on a single# line, and change only the value of the NAME= key. # PCI device 0x8086:0x100e (e1000) SUBSYSTEM== "net", ACTION== "add", DRIVERS== "? *", ATTR {address} = = "08VO 00VO 74V 39RV 02", ATTR {type} = = "1", KERNEL== "eth*", NAME= "eth0"

As shown above

A) delete the configuration of eth0 in the original file (because it is useless, this configuration is the configuration of the source machine when I cloned this server in this test, and the corresponding mac address in the configuration is also the mac address of the source server, which is of no use to our current server)

B) change the name of the eth2 Nic to eth0. (notice that its mac address is 08-0-00-27-7-4-39-22, which is exactly the entry we want to modify. )

2) modify the interface configuration file ifcfg-eth0 to change the Nic from eth2 to eth0

3) restart the machine and let the server reconfigure the Nic information according to the / etc/udev/rules.d/70-persistent-net.rules file

You can find that as soon as you enter the server after restarting the machine, the network has been configured to be consistent, as shown below:

This is the end of the article on "how to modify the name of the network card under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report