Skip to Content

How to Rename a Network Interface in Linux

How to Rename a Network Interface in Linux

This article provides a comprehensive guide on renaming network interfaces in Red Hat Enterprise Linux (RHEL), focusing on the differences between the traditional ifcfg format and the newer keyfile format for NetworkManager connection profiles.

Understanding RHEL’s Network Interface Naming

Traditionally, Linux kernels assigned interface names like eth0, eth1, etc., based on the order of detection during system startup. This approach often led to inconsistent naming across reboots, especially with hardware changes.

RHEL addresses this issue with predictable network interface naming. This scheme utilizes firmware, topology, and location information to assign consistent names, such as eno1, ens1, etc. While predictable naming enhances clarity, there might be situations where you prefer custom names for specific interfaces.

Renaming Interfaces with the ifcfg Format (Deprecated)

In the older ifcfg format, interface renaming was directly controlled by a udev rule that invoked a helper utility. This utility scanned the /etc/sysconfig/network-scripts/ directory for ifcfg-* files, matching MAC addresses to rename interfaces based on the DEVICE parameter within those files.

Boost Your Website Speed!

If you want your website to run as fast as ours, consider trying Cloudways. Their powerful cloud infrastructure and optimized stack deliver exceptional performance. Free migration!

Example (ifcfg-eth0):

DEVICE=eth0
HWADDR=00:00:5e:00:53:1a
# ... other settings

udev Rule (/usr/lib/udev/rules.d/60-net.rules):

# This rule calls the rename_device helper utility
SUBSYSTEM=="net", ACTION=="add", RUN+="/lib/udev/rename_device"

The helper utility would then rename the interface with MAC address 00:00:5e:00:53:1a to eth0 as specified in the DEVICE parameter.

Note: The ifcfg format is deprecated in RHEL 9. It’s recommended to migrate to the keyfile format for improved functionality and consistency.

Renaming Interfaces with the keyfile Format

The keyfile format offers a more modern and flexible approach to network configuration. Unlike ifcfg, it doesn’t directly manage interface renaming. Instead, you use external tools like udev rules or systemd link files to rename interfaces, and then reference the custom names within your keyfile profiles.

By using either of these methods, you can customize network interface names in RHEL to improve clarity and managebility.

Renaming network interfaces

Using udev Rules:
  • Location: /etc/udev/rules.d/
  • Naming Convention: Unique name with the .rules extension.
  • Purpose: udev rules can be used to match specific hardware attributes and execute actions, such as renaming a network interface.

Example (/etc/udev/rules.d/70-persistent-net.rules):

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:00:5e:00:53:1a", ATTR{type}=="1", NAME="provider0"
Using systemd Link Files:
  • Location: /etc/systemd/network/
  • Naming Convention: 70- prefix, followed by a descriptive name and the .link extension.
  • Purpose: systemd link files are designed to configure network interfaces, including renaming them.

Example (/etc/systemd/network/70-provider0.link):

[Match]
MACAddress=00:00:5e:00:53:1a

[Link]
Name=provider0
Common Considerations:
  • MAC Address: Both examples rely on matching the MAC address of the network interface. Ensure you replace “00:00:5e:00:53:1a” with the actual MAC address of your target interface.
  • Custom Name: Replace “provider0” with the desired custom name you want to assign to the interface.
  • Regenerate initrd: In both cases, if you need networking within the initial RAM disk (initrd), regenerate it after making these changes using the command dracut -f.

2. Update the NetworkManager Connection Profile:

Modify the relevant NetworkManager connection profile in the /etc/NetworkManager/system-connections/ directory. Within the [connection] section, set the interface-name property to the new custom name.

Example (/etc/NetworkManager/system-connections/example_profile.nmconnection):

[connection]
id=example_profile
type=ethernet
interface-name=provider0  # Reference the custom name

[ipv4]
method=auto

[ipv6]
method=auto

# ... other settings

3. Reload NetworkManager:

Apply the changes by executing the following command:

# nmcli connection reload

4. Verify the Changes:

Confirm the interface name has been updated:

# ip link show

Additional Notes:

  • Always back up your network configuration files before making any modifications.
  • Ensure consistent naming across all configurations, scripts, and applications.
  • Thoroughly test network functionality after renaming interfaces.
  • Consult the RHEL documentation and the man pages for udev, systemd, and NetworkManager for detailed information on configuring and managing network interfaces.

Conclusion

Renaming network interfaces in RHEL requires understanding the differences between the ifcfg and keyfile formats and utilizing appropriate tools.

By following the steps outlined in this article, you can effectively rename interfaces while ensuring a consistent and well-configured network environment. 

Edward Dan

Saturday 2nd of November 2024

Great tutorial! Renaming network interfaces can be really useful for better organization, especially on systems with multiple connections. Just a tip: always remember to update your network configuration files afterward to ensure everything works smoothly after the rename. Thanks for the clear instructions!