
ifrename Command in Linux
The ifrename command in Linux renames the network interfaces based on various static criteria such as MAC addresses, interface index numbers, or other hardware characteristics. By default, network interface names are assigned dynamically, with each interface receiving the first available name, such as eth0, eth1, and so on.
The sequence in which network interfaces are created may vary. For built-in interfaces, this order may differ depending on the kernel's boot-time detection. For removable interfaces, users can connect them in any sequence.
The ifrename command is used to choose specific names for network interfaces. Various selectors determine how interface names correspond to system network interfaces. The most commonly used selector is the interface's MAC address.
Table of Contents
Here is a comprehensive guide to the options available with the ifrename command −
- Syntax of ifrename Command
- ifrename Command Options
- Examples of ifrename Command in Linux
- Using udev Rules to Rename the Network Interface
Note − In modern Linux distributions, the ifrename tool is considered deprecated in favor of udev rules for consistent network interface naming. It is recommended to use udev for managing network interface names, as it offers more reliable and versatile methods for naming interfaces.
Syntax of ifrename Command
The ifrename command has two syntaxes, one for renaming the network interface and the other for configuration.
To rename the network interface, use the syntax given below −
ifrename [options] [-i interface] [-n newname]
The [options] field is used to specify various options, such as mentioning the configuration file. The [-i interface] option is used to specify the original interface name, while [-n newname] is used to specify the new name.
For general configuration or testing, use the syntax given below −
ifrename [options]
The [options] field is used to specify various options, which are given in the next section.
ifrename Command Options
The options of the ifrename command are listed below −
Options | Description |
---|---|
-c configfile | Sets the configuration file for mapping selectors to interface names; default is /etc/iftab (Use dash "-" to read from stdin) |
-p | Loads kernel modules before renaming interfaces. By default, ifrename only checks already loaded interfaces |
-d | Activates Debian-specific options (with -p, only loads modules specified in /etc/network/interfaces) |
-i interface | Renames only the specified interface and prints the new name |
-n newname | When combined with -i, directly renames the interface to newname, bypassing config mappings. Without -i, only uses mappings that match newname |
-t | Enables interface name swapping (takeover) if one interface "steals" the name of another (only for kernel 2.6.X and disabled with Hotplug) |
-u | Activates udev mode, allowing ifrename to assign names directly within the udev framework |
-D | Dry-run mode; no changes are made, but new names (if any) are printed |
-V | Verbose mode for detailed output, especially useful with dry-run for debugging configurations |
Examples of ifrename Command in Linux
This section will demonstrate the usage of the ifrename command in Linux with examples −
Using a Custom Configuration File
The ifrename command uses the /etc/iftab configuration file by default. To read from a custom configuration file, use the -c option.
ifrename -c /home/user/config.conf
Renaming an Interface
To rename the interface, use the -i and -n options with the ifrename command −
ifrename -i enp0s1 -n mynetwork
The above command renames the esp0s1 interface to mynetwork.
Taking Over Name
To swap the names of two interfaces using ifrename command, use the -t option −
ifrename -t -i enp0s1 -n enp0s2
The above command enables name takeover, allowing enp0s1 and snp0s2 to swap names. This works only with kernel 2.6.X and above if the other interface is down.
Loading Kernel Module before Renaming
To load kernel modules before renaming the network interfaces, use the -p option −
ifrename -p
Dry Running the ifrename Command
To dry-run the ifrename command, use the -D option −
ifrename -D
The above command will not change any interface, it will only print a new interface name, even if it is the same as the old name.
Using udev Output Mode
To enable udev output mode, use the -u option −
ifrename -u
In the udev mode, the output of ifrename can be parsed directly by udevd as an IMPORT action. Note that it requires udev version 107 and above.
Getting Verbose Output
To get the verbose output, use the -V option with the ifrename command −
ifrename -V
Combining the verbose (-V) option with dry-run (-D) mode in ifrename provides detailed information about how ifrename interprets the configuration file and what renaming actions it would perform, without making any actual changes.
ifrename -V -D
It effectively diagnoses trivial issues, such as syntax errors or unexpected behavior in interface renaming, without disrupting network connections.
Using udev Rules to Rename the Network Interface
Using udev rules to rename the network interface is more reliable than ifrename, as it maintains consistent naming across reboots and hardware changes.
To rename the network interface name using udev rule follow the steps given below −
Check the MAC address and note it using the following command −
ip link show

Create a new .rules file in the /etc/udev/rules.d directory −
sudo nano /etc/udev/rules.d/10-network-rename.rules
The .rules file name must start with a number.
To change the interface name with a specific MAC address, insert the following line in the file −
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="1e:36:b2:f4:bc:67", NAME="mynetwork"

The above line changes the network interface with MAC address 1e:36:b2:f4:bc:67 to mynetwork.
Reload the services −
sudo udevadm control --reload-rules sudo udevadm trigger
You may need to reboot the system −
sudo reboot
Verify the changes using the ip link show command.

Alternatively, the rename can also be done by modifying the /etc/netplan/*.yaml file with the following configuration −
network: version: 2 renderer: NetworkManager ethernets: enp0s1: dhcp4: true dhcp6: true match: macaddress: a4:bb:6d:88:5b:60 set-name: mynetwork
Conclusion
The ifrename command in Linux is used to rename network interfaces based on specific criteria. However, it is important to note that the ifrename is considered deprecated in favor of using udev rules, which provides a more robust and flexible approach to managing network interface names.
This tutorial covered the ifrename command, its syntax, options, and usage in Linux with examples.