CentOS 7 – How to Rename Network Interface Without Rebooting

centosconfigurationnetwork-interface

I'm renaming network interfaces by modifying the files in /etc/sysconfig/network-scripts.

  • eth0 -> nic0
  • eth1 -> nic1

The content of the network scripts looks like this, after modification:

# cat /etc/sysconfig/network-scripts/ifcfg-nic0
DEVICE=nic0
BOOTPROTO=static
ONBOOT=yes
HWADDR=xx:xx:xx:xx:xx:xx
USERCTL=no
IPV6INIT=no
MASTER=bond0
SLAVE=yes

A reboot activates the new config. But how do I activate this configuration without rebooting?

A systemctl restart network doesn't do the trick.

I can shut down one interface by its old name (ifdown eth0) but ifup results in below message no matter if the old or new name was provided:

ERROR : [/etc/sysconfig/network-scripts/ifup-eth] Device nic0 does not seem to be present, delaying initialization.

/etc/init.d/network status shows this output:

Configured devices:
lo bond0 nic0 nic1
Currently active devices:
lo eth0 eth1 bond0

Both, ifconfig and ip a show the old interface names.

Best Answer

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.

Related Question