You get a bonus - 1 coin for daily activity. Now you have 1 coin

CentOS/RedHat: replacing a network card, or why network card settings break after replacing it

Practice



Why do network card settings break after replacing it?

If you need to replace a network card in a computer running CentOS or RedHat, you should be aware of the following fact:

CentOS/RedHat ties network settings to the network card's MAC address.

This means that as long as you had a network card named eth0 with a MAC address, say, "A" - the settings worked. Now you replace the network card, and its MAC address is, of course, different, say, "B". But the operating system only knows the settings for the network card with MAC="A".

What does CentOS do? It keeps the network card number the same (eth0, for example), but recreates the settings file, setting it to "obtain settings via DHCP" with the new MAC.


What to do?

Go to the /etc/sysconfig/network-scripts directory. There, find the configuration file for your network card and notice that next to it lies a file with the same name but with the ".bak" suffix as the extension.

In fact, all the settings of the previous network card are safely preserved in the file with the ".bak" extension. All you need to do is open the file without that extension, copy the MAC address from it, and write it into the ".bak" file. After that, delete the new file (without bak), and remove the ".bak" extension from the old file. Remember - in the old file you changed the MAC address to the MAC of the new network card, and it will now work again.

Here's an example:

$ cd /etc/sysconfig/network-scripts
$ cat ifcfg-eth0 | grep HWADDR
HWADDR=fe:16:3e:68:fc:fb
$ sudo rm ifcfg-eth0
$ sudo mv ifcfg-eth0.bak ifcfg-eth0
$ sudo nano ifcfg-eth0

# and here we replace HWADDR with the new MAC

And restart the network subsystem:

$ sudo /etc/init.d/network restart

PS. You need to delete the newly created file with the new MAC address (not the one where you wrote the MAC) - otherwise it will get in the way when the interface starts, resetting the settings to default. That is, the "rm ..." command must be executed! Or move that file somewhere out of the way, for example, to your home directory.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computer networks"

Terms: Computer networks