How to regenerate network card configuration files in CentOS 7?
To regenerate the network card configuration file for CentOS 7, follow these steps:
- Open a terminal window and log in to the system as an administrator.
- Navigate to the directory where the network card configuration file is located and use the following command:
cd /etc/sysconfig/network-scripts/
- To check the current network card configuration file, use the following command:
ls ifcfg-*
- If you need to regenerate the configuration file for a specific network card, you can first backup the original configuration file and then use the following command (assuming the network card that needs to be regenerated is eth0):
cp ifcfg-eth0 ifcfg-eth0.bak
- Delete the existing network card configuration file and use the following command:
rm -f ifcfg-eth0
- Create a new network interface configuration file using a text editor (such as vi) by using the following command:
vi ifcfg-eth0
- “Enter the new network card configuration information in the editor, for example:”
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
This is an example configuration that automatically obtains an IP address using DHCP. Modify the configuration information according to actual needs.
- Save and close the editor.
- To restart the network service, use the following command:
systemctl restart network
After regenerating the network card configuration file, the network card will start with the new configuration.