How to Ensure Consistent Network Interface Assignments in OpenWrt?

I'd like to configure my router's network interfaces as shown in the diagram below.


Currently, I need to produce dozens of these routers, and they should all have the same physical interface assignments:

lan: eth0
wan1: eth1
wan2: eth2
wan3: eth3
wan4: eth4
wan5: eth5
wan6: eth6
wan7: eth7
I've set up failover functionality using mwan3. However, I'm concerned that the order of eth0, eth1, and eth2 might change. How does OpenWrt determine the order of eth0, eth1, and eth2?

I've read suggestions to fix this issue using MAC addresses, but since each machine will have a different MAC address, I'd have to configure it individually. Is there a more efficient way to create installation images for each machine with consistent interface assignments? Any good ideas or advice would be greatly appreciated. please..TT Thank you!

The interfaces are listed in the order in which the hardware is discovered.
PCI NICs are typically stable, but USB NICs not so much.
You can automate the setup with scripting like this:


Thank you very much for answering my question. I asked the manufacturer if the process of processing the PIC NIC of the product is the same, and I want to process it as you to

At "/sys/class/net" you can find network adapters by the "path" used to find them on the system.


Thank you for your response. I have limited knowledge in this area, and I'm finding it challenging to understand how to change the 'path'. Could you possibly provide a script related to this and explain how to use it? I would really appreciate your assistance. Thank you!

I'm not good at this either, as an option
i would consider the network metric option.
lan - metric 0
wan1 - metric 1
wan2 - metric 2
and so on

1 Like

Set up the hotplug script linked above, then reconfigure devices like this:

while uci -q delete network.@device[0]; do :; done
find /sys/class/net/*/device/uevent \
| awk -F '/' '{print $5}' \
| sort -u \
| while read -r DEV_NAME
do DEV_MAC="$(cat /sys/class/net/${DEV_NAME}/address)"
case ${DEV_NAME} in
(eth0|lan) DEV_NAME="lan"
uci set network.${DEV_NAME}_br="device"
uci set network.${DEV_NAME}"br-${DEV_NAME}"
uci set network.${DEV_NAME}_br.type="bridge"
uci add_list network.${DEV_NAME}_br.ports="${DEV_NAME}"
uci set network.${DEV_NAME}.device="br-${DEV_NAME}" ;;
(eth*|wan*) DEV_NAME="wan${DEV_NAME##*[^0-9]}"
uci set network.${DEV_NAME}.device="${DEV_NAME}"
uci set network.${DEV_NAME}6.device="${DEV_NAME}" ;;
uci set network.${DEV_NAME}_dev="device"
uci set network.${DEV_NAME}"${DEV_NAME}"
uci set network.${DEV_NAME}_dev.mac="${DEV_MAC}"
uci commit network
service network restart

Thank you so much for your help. I've implemented the following script in rc.local to set network names based on the PCI Path. I really appreciate it! I'm not entirely sure if this is the correct implementation, but I confirmed that it works well. Thank you so much!

for dev in $(ls -1 /sys/class/net); do
ip link set dev "$dev" down

if [ "$dev" != "lo" ] && [ "$dev" != "br-lan" ]; then
    ip link set dev "$dev" name "${dev}_tmp"


for dev in $(ls -1 /sys/class/net); do
path=$(basename $(readlink -f "/sys/class/net/$dev/device" 2>/dev/null))

if [ "$dev" = "lo" ] || [ "$dev" = "br-lan" ]; then

case "$path" in
        ip link set dev "$dev" name eth0
        ip link set dev "$dev" name eth1


for dev in $(ls -1 /sys/class/net); do
ip link set dev "$dev" up

/etc/init.d/network restart

exit 0

1 Like

Thank you for your advice. I initially implemented the change based on MAC addresses, but then realized that these can vary from device to device. So, I explored a different method. Thanks to your suggestion, I learned about various approaches and gained a bit more understanding in this field. I really appreciate your help. Thank you! :smile:


Thank you for your advice. However, I understand that using metric values to set up interfaces is a method applied in mwan3. I was looking for a way to assign fixed names to network interfaces so that the same interface is consistently recognized by the same name every time the system boots. If I'm misunderstanding your suggestion due to my limited knowledge in this area, please kindly clarify it for me. This field seems to require a lot of learning and understanding :sob:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.