CentOS 7 - Rename network interface without rebooting
You can rename the device using the ip command:
/sbin/ip link set eth1 down
/sbin/ip link set eth1 name eth123
/sbin/ip link set eth123 up
Edit:
I am leaving the below for the sake of completeness and posterity (and for informational purposes,) but I have confirmed swill's comment and Marco Macuzzo's answer that simply changing the name and device of the interface /etc/sysconfig/network-scripts/ifcfg-eth0 (and renaming the file) will cause the device to be named correctly as long as the hwaddr= field is included in the configuration file. I recommend using this method instead after the referenced update.
You may also want to make sure that you configure a udev rule, so that this will work on the next reboot too. The path for udev moved in CentOS 7 to /usr/lib/udev/rules.d/60-net.rules but you are still able to manage it the same way. If you added "net.ifnames=0 biosdevname=0" to your kernel boot string to return to the old naming scheme for your nics, you can remove
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", PROGRAM="/lib/udev/rename_device", RESULT=="?*", NAME="$result"
And replace it with
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:50:56:8e:3f:a7", NAME="eth123"
You need one entry per nic. Be sure to use the correct MAC address and update the NAME field. If you did not use "net.ifnames=0 biosdevname=0", be careful as there could be unintended consequences.
Actually, the best answer I believe is the combination of the two answers already posted. In order to change the device name without restarting network services, use the ip link
commands suggested by James Shewey (ip link set <old_device_name> name <new_device_name>
).
To make the changes survive a reboot in Red Hat Linux, modify the relevant file in /etc/sysconfig/network-scripts/
. Rename the file ifcfg_<old_device_name>
to ifcfg_<new_device_name>
and change the DEVICE
variable inside to <new_device_name>
. Also, make sure the HWADDR
variable is set and is correct. There is no need to touch udev rules, since 60-net.rules
is actually there to read the ifcfg configuration files in /etc/sysconfig/network-scripts
.
ip link set ens33 down
ip link set ens33 name eth0
ip link set eth0 up
mv /etc/sysconfig/network-scripts/ifcfg-{ens33,eth0}
sed -ire "s/NAME=\"ens33\"/NAME=\"eth0\"/" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -ire "s/DEVICE=\"ens33\"/NAME=\"eth0\"/" /etc/sysconfig/network-scripts/ifcfg-eth0
MAC=$(cat /sys/class/net/eth0/address)
echo -n 'HWADDR="'$MAC\" >> /etc/sysconfig/network-scripts/ifcfg-eth0