I'm Running multiple Raspberry Pi 3's with Raspbian jessie. There is a wifi interface on board, and I added another wifi USB dongle. On all devices, these defaulted to wlan0 and wlan1 respectively.

After installing some tool on one of the devices (using apt-get) the names switched, so now the USB dongle became wlan0 and the on-board wifi became wlan1.

I understand that I could not rely on these names to be the same everywhere, but I need to make some assumptions, as the USB dongle has different capabilities than the on-board card. How could I programmatically make my code target the right device each time?

If I have an SD card with a running environment, am I guaranteed to get the same network names if I plug the SD into another (identical) set of hardware? (evidence suggests otherwise)..

Can I run some script to assign the names the way I want (based on the hardware differences) so I can run the software predictably?

Can I switch the names back after they changed?

Please provide Raspbian specific commands. I have been trying random Linux/Ubuntu advice which didn't work or worse :(

  • It's a udev rule. The tool you installed may have removed the original rule and installed a new rule. All you have to do is recreate the rule. There's no specific command to change it. It's a text file that you can modify with your favorite editor.
    – alvits
    Jul 13, 2016 at 0:58
  • 1
    use the MAC address blog.sleeplessbeastie.eu/2013/01/11/…
    – Ellery Familia
    Jul 14, 2016 at 2:45

2 Answers 2


You can assign device names by using udev and defining you own rules. Please see debianhelp udev for an detailes description of how to do that.

Check the script/etc/udev/rules.d/70-persistent-net.rules, which records and reserves interface names for future use.

You can also write a new udev rule to give your devices fixed names, based on the mac address. To do this add a file in /etc/udev/rules.d/ called 10-network-device.rules with smething like that: SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="12:34:56:78:9a:bc", NAME="myusbwifi".

Finally this forum article may help.

  • How would the rule look if I want to base it on the hardware type/model, and how would I find the right value to provide for a specific wireless adapter?
    – Ron Harlev
    Jul 25, 2016 at 21:39

As long as you request "programmatically make my code target the right device each time", I suggest you to activate predictable network names:

# raspi-config

Then choose:

2  --> Network Options
N3 --> Enable/Disable predictable network

After rebooting the network device names will include the MAC Address, like:

$ ifconfig
enxb827ebff1dd5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::d4b:5c22:8c71:3470  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:ff:1d:d5  txqueuelen 1000  (Ethernet)
        RX packets 12260  bytes 12573583 (11.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8150  bytes 743690 (726.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

You can even predict the name based on the MAC Address of each card, like in enxb827ebff1dd5 for b8:27:eb:ff:1d:d5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.