Custom Interface Name

We want to set a custom interface name for the interface eth0. The name should be custom one such as “external-2“. How this can be achieved using NetworkManager and without it.

Existing Connection Profile (With NetworkManager)

To set a custom device name with NetworkManager for an existing connection profile please do the following:

1. Ensure the existing connection profile has stored the MAC address of the physical interface it is associated with. In the example below, the connection profile is named “Wired connection 1”:

# nmcli connection show "Wired connection 1" | grep 802-3-ethernet.mac-address:
802-3-ethernet.mac-address:             --

2. If the MAC address is missing, add it. First find the MAC address with the “ip link” command and then use the nmcli command to modify the connection profile:

# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:73:59:15 brd ff:ff:ff:ff:ff:ff
# nmcli connection modify "Wired connection 1" 802-3-ethernet.mac-address "52:54:00:73:59:15"

3. Now modify the connection profile’s connection.interface-name property to set the desired device name. In this example below, the device is named “external-2“:

# nmcli connection modify "Wired connection 1" connection.interface-name "external-2"

4. Reboot the system:

# shutdown -r now

5. Verify the device has been named as expected:

# ip link
3: external-2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:73:59:15 brd ff:ff:ff:ff:ff:ff

Recommended Reading: Install PHP 7 on CentOS 7

New interface without an existing Connection Profile (With NetworkManager)

To set a custom device name with NetworkManager for a new interface which does not have an existing connection profile please do the following:

1. Note the MAC address of the device using the “ip link” command. In the following example, eth0 is used and the MAC address is seen to be 52:54:00:2f:4b:68:

# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:2f:4b:68 brd ff:ff:ff:ff:ff:ff

2. Use the nmcli command to create a new connection profile for eth0. Be sure to specify the MAC address. In the following example, the network device with the specified MAC address will be renamed to “internal-1” upon rebooting the system:

# nmcli connection add type ethernet mac "52:54:00:73:59:15" ifname "internal-1"

3. Reboot the system

# shutdown -r now

4. Verify the device name is now “internal-1”

# ip link
2: internal-1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:2f:4b:68 brd ff:ff:ff:ff:ff:ff

Custom Device Name without NetworkManager

1. In the interface’s current interface configuration file (/etc/sysconfig/network-scripts/ifcfg-* file), ensure both the DEVICE and HWADDR parameters are properly set. DEVICE is the name to be given to the interface with the MAC address equal to HWADDR.

2. Alternatively, setting a custom interface name with a udev rule is still possible. Create a udev rules file /usr/lib/udev/rules.d/60-net.rules in the /etc/udev/rules.d/ directory. The rule can match against the device MAC address or PCI bus address:

# vi /usr/lib/udev/rules.d/60-net.rules
# MAC address match. Will name the device with the specified MAC address the value given in the NAME property:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:b1:05:63:31", ATTR{type}=="1", KERNEL=="*", NAME="myeth2"

# PCI bus address match. Bus address can be seen in the output of the lspci command.
SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", SUBSYSTEMS=="pci", KERNELS=="0000:00:03.0", NAME="private-3"

The /usr/lib/udev/rules.d/60-net.rules udev rule file will check each ifcfg file for the presence of the DEVICE and HWADDR parameters. If the interface in question has a MAC address which matches the value of the HWADDR property then it will be assigned the name given by the value of the DEVICE property.

LEAVE A REPLY

Please enter your comment!
Please enter your name here