Persistent Ethernet Interface Naming by MAC Address

This guide explains how to assign persistent interface names to Ethernet devices based on their MAC addresses during system boot.

This is useful when:

  • interface names change between reboots
  • multiple USB/Ethernet adapters are used
  • deterministic interface naming is required

The script will rename only interfaces explicitly defined in the configuration file.

Create the following file:

/etc/init.d/staticeth

Insert the following content:

#!/bin/sh /etc/rc.common
 
START=11
 
# don't run within buildroot
[ -n "${IPKG_INSTROOT}" ] && return 0
 
# use busybox grep as GNU grep may behave differently
grep(){
    /bin/busybox 'grep' $@
}
 
# shutdown interfaces and assign temporary names
for i in $( ls /sys/class/net/*/device/uevent | awk -F'/' '{print $5}' | tr '\n' ' ' ) ;
do
 
    mac_address=$( grep $i /etc/config/mac-static-interfaces | awk '{print $3}' | tr -d '"' )
 
    if [ "$mac_address" != '' ]; then
 
        ip link set "$i" down
        ip link set "$i" name old"$i"
 
    fi
done
 
# assign configured interface names based on MAC address
for i in $( ls /sys/class/net/*/device/uevent | awk -F'/' '{print $5}' | tr '\n' ' ' ) ;
do
 
    mac_address=$( cat /sys/class/net/$i/address )
    interface_name=$( grep -i $mac_address /etc/config/mac-static-interfaces | awk '{print $2}' )
 
    if [ "$interface_name" != '' ]; then
 
        ip link set "$i" down
        ip link set "$i" name "$interface_name"
 
    fi
done
chmod +x /etc/init.d/staticeth

Enable the service at boot:

service staticeth enable

Create the following file:

/etc/config/mac-static-interfaces

Example configuration:

config mac-static-interfaces
    option eth0 "70:85:c2:8a:57:4d"
    option eth6 "00:0e:c6:70:2a:22"
    option eth8 "00:0e:c6:c3:82:a6"

Configuration syntax:

option <interface_name> "<mac_address>"

Example:

option eth1 "AA:BB:CC:DD:EE:FF"

After completing the configuration reboot the device:

reboot

Verify interface names after reboot:

ip link show
  • It is recommended to configure all physical interfaces.
  • Virtual interfaces and bridges are automatically excluded.
  • The script relies on MAC addresses as unique identifiers.
  • Designed for OpenWrt systems using BusyBox.

This method is based on the original forum post by bobafetthotmail: https://forum.openwrt.org/t/stable-network-interface-names-for-usb-ethernet-dongles/98539/18

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2026/05/17 21:27
  • by compact21