HowTo Change Network Interface Name in Linux Permanently

Version 9

    In some Linux distributions, interface names generated by auto-naming can be long and inconvenient. This post will illustrate one way to change interface names.

     

    References

     

    Setup

    The setup should include a server equipped with a Mellanox adapter with the latest MLNX_OFED software stack installed.

     

    Configuration

    1. Find the MAC address of the ports you wish to change their names (e.g., enp2s0f0 and enp2s0f1):

    # ifconfig

    enp2s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

            inet 1.1.1.2  netmask 255.255.255.0  broadcast 1.1.1.255

            inet6 fe80::7efe:90ff:fecb:7602  prefixlen 64  scopeid 0x20<link>

            ether 7c:fe:90:cb:76:02  txqueuelen 1000  (Ethernet)

            RX packets 38  bytes 7321 (7.1 KiB)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 1  bytes 70 (70.0 B)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

     

     

    enp2s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

            ether 7c:fe:90:cb:76:03  txqueuelen 1000  (Ethernet)

            RX packets 0  bytes 0 (0.0 B)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 0  bytes 0 (0.0 B)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

     

    2. Create the configuration file (70-persistent-net.rules)

    # vi /etc/udev/rules.d/70-persistent-net.rules

     

    Add the following line per relevant port. Add the MAC address and the new NAME per port.

    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="7c:fe:90:cb:76:02", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="7c:fe:90:cb:76:03", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

     

    3. Create/edit the ifcfg file for the port configuration:

    #cat /etc/sysconfig/network-scripts/ifcfg-eth1

     

    DEVICE="eth1"

    BOOTPROTO="static"

    HWADDR="7c:fe:90:cb:76:02"

    IPADDR=1.1.1.2

    NETMASK=255.255.255.0

    ONBOOT="yes"

     

    4. Reboot the server and then verify the name changes by running ifconfig.

    # ifconfig

     

    eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

            inet 1.1.1.2  netmask 255.255.255.0  broadcast 1.1.1.255

            inet6 fe80::7efe:90ff:fecb:7602  prefixlen 64  scopeid 0x20<link>

            ether 7c:fe:90:cb:76:02  txqueuelen 1000  (Ethernet)

            RX packets 0  bytes 0 (0.0 B)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 23  bytes 3208 (3.1 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

     

    eth2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

            ether 7c:fe:90:cb:76:03  txqueuelen 1000  (Ethernet)

            RX packets 0  bytes 0 (0.0 B)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 0  bytes 0 (0.0 B)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0