ajtaggart
Posts: 11
Joined: Wed Mar 07, 2018 1:24 am

Set Static network interface names

Wed Mar 21, 2018 12:05 am

So I have multiple wifi adaptors on one rpi3 and sometimes the interface names swap around. sometimes the built in wifi is wlan0 and sometimes its not. I need them to be static and i cant use predictable network names because i cant assume to know the mac addresses if its on another machine.

How can i set static interface names for wlan0 - wlanX, i tried looking into using udev but didn't make any progress. I;m running the latest release of raspbian stretch.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Set Static network interface names

Wed Mar 21, 2018 11:28 am

I've been using this with great success lately. I don't care for the predictable name format.
Create the file /etc/udev/rules.d/72-static-name.rules
Add these lines, replacing the mac addresses with the mac addresses of your interfaces.

Code: Select all

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*",
ATTR{address}=="00:c0:ca:96:d8:8b", KERNEL=="w*",NAME="wlan0"

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*",
ATTR{address}=="b8:27:eb:1e:56:52", KERNEL=="w*",NAME="wlan1"

ajtaggart
Posts: 11
Joined: Wed Mar 07, 2018 1:24 am

Re: Set Static network interface names

Thu Mar 22, 2018 6:07 pm

Awesome thanks man !

ajtaggart
Posts: 11
Joined: Wed Mar 07, 2018 1:24 am

Re: Set Static network interface names

Thu Mar 22, 2018 6:13 pm

IN CASE ITS HELPFUL TO ANYONE. Essentially i had a problem where the built in wifi and a wifi adapter were swapping names this was a problem because the wifi adapter could not function as an access point (AP) so it had to be on wlan1. Here is the code I wrote up to fix this problem. Just place "python /code.py" at the bottom of rc.local for it to work. Yes I know its not perfect :3 I mainly code in C so i'm not a python pro.

import os, sys

def getmac(ip_output):
output = ip_output.split("\n")
for x in range(len(output)):
if ("NO-CARRIER" in output[x]) and ("wlan" in output[x]):
content = output[x+1].split(" ")
return content[len(content)-3]
for x in range(len(output)):
if("wlan1" in output[x]):
content = output[x+1].split(" ")
return content[len(content)-3]



if(os.path.isfile("/etc/udev/rules.d/72-static-name.rules") == False):
stream = os.popen("ip addr", 'r')
ip_output = stream.read()
mac = getmac(ip_output)
f = open("/etc/udev/rules.d/72-static-name.rules","w")
f.write("ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{address}==\"%s\", KERNEL==\"w*\",NAME=\"wlan1\"" % mac)
f.close()
stream.close()

Return to “Advanced users”