Problem
User wants to rename the network interface name on cent0s7/8 without rebooting.
One of the reasons is to create network compatibility for applications like kubernetes who looks for identical hardware on all nodes
Solution
run the following commands to rename the network interface. rename and set accordingly
ip link set ens192 down
ip link set ens192 name eth0
ip link set eth0 upmv /etc/sysconfig/network-scripts/ifcfg-{ens192,eth0}
sed -ire "s/NAME=\"ens192\"/NAME=\"eth0\"/" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -ire "s/DEVICE=\"ens192\"/DEVICE=\"eth0\"/" /etc/sysconfig/network-scripts/ifcfg-eth0
MAC=$(cat /sys/class/net/eth0/address)
echo -n 'HWADDR="'$MAC\" >> /etc/sysconfig/network-scripts/ifcfg-eth0
Attachment: commands.txt
With rebooting option and permanently
edit the file
/etc/sysconfig/network-scripts/ens192-ifcfg
and set the name and the device for the new name. for example: eth0
edit the file
/etc/sysconfig/network
and set GATEWAYDEV to the new name
We do this for a living.
Kubernetes, DevOps and platform engineering, delivered in days — not another weekend lost to a stack trace.
Start a project →