Change mac address problem

When i try to change mac address, I always get the same error:
[ERROR] Could not change MAC: interface up or insufficient permissions: Is a directory
i tried:
ifconfig wlan0 down ifconfig wlan0 hw ether "xx:xx:xx:xx:xx:xx"
and with macchanger
macchanger wlan0 -m xx:xx:xx:xx:xx:xx
Thanks a lot

Just add this line
option macaddr 'XX:XX:XX:XX:XX:XX'
in the "config wifi-iface" section of /etc/config/wireless

1 Like

/etc/config/wireless
config wifi-iface option network 'wwan' option ssid 'XXXXX' option encryption 'psk2' option device 'radio0' option mode 'sta' option bssid 'XX:XX:XX:XX:XX:XX' option key 'XXXXXXXX' option macaddr 'XX:XX:XX:XX:XX:XX'

not work for me

Did you do a
/etc/init.d/network restart
or
reboot the router?

Thanks a lot.
Yes...I know how to change it, I've also tested before you say it! But it doesn't change in any way!

I think I have to do something else in this case.

If you put the wifi interface in access point (ap) mode, does it work?
Also (perhaps a stupid question, sorry for that), are you sure the MAC is a valid one? (0-9/A-F)

good answer :smiley:
i don't know if work in ap because it is a raspberry pi and when i activate a new ap (with wwan activated) it won't work
i generated mac with a program
also if i do
uci set wireless.@wifi-iface[0].macaddr='xx:xx:xx:xx:xx:xx' uci commit wireless
it not work :cry:

If I were you I would first test the MAC option with the radio configured as an AP.

The radio works OK?
I mean you can connect to WWAN without any problems?

And the WiFi module... is?
Atheros - Ralink - Something else?

Radio is ok
Wwan is ok
Wifi module is broadcom (stock raspberry pi)

Would you like to see with TeamViewer ?

I don't feel comfortable having access to other's PC/network.
And I can't help you much with RPi anyway, so wait if someone else has an idea... :slight_smile:

Incredible, I've solved it!
With an old script I used to generate mac addresses


I had already tried it before posting but after several reboots, it changed the mac address independently

1 Like

Cool, glad you made it. :slight_smile:

angelos: To answer your question in AP mode currently the LEDE scripts do not support a "macaddr" option in "wifi-iface" sections. It does support one in a "wifi-device" sectin but that is for different uses. I did manage to hack support for it into netifd/hostapd.sh (see following diff) but unfortunately I could not figure out how to get it not to add a "bssid=" line when the option is not present, so you have to make sure to supply one for all "wifi-iface" sections. If someone can figure out how to finish this off, it would be useful for units that store their real MAC address somewhere LEDE does not know about and pairs of which will fire up with the same default address.

209c209
<               macfilter ssid wmm uapsd hidden short_preamble rsn_preauth \
---
>               macfilter macaddr ssid wmm uapsd hidden short_preamble rsn_preauth \
363a364,365
>       [ -n "$macaddr" ] && append bss_conf "bssid=$macaddr" "$N"
>

Basically, it wasn't a/my "question".
The macaddr option in the "wifi-iface", works for me...

Are we talking about the same thing or am I missing something or maybe didn't understand what you mean? I'm using 17.01.1, has something changed?

Angelos is right.
I solved my problem with this:
uci set wireless.@wifi-iface[0].macaddr='xx:xx:xx:xx:xx:xx' uci commit wireless
You can control that it's the same by typing uci show in terminal

Which is equivalent to entering in /etc/config/wireless:
config wifi-iface option network 'wwan' option ssid 'XXXXX' option encryption 'psk2' option device 'radio0' option mode 'sta' option bssid 'XX:XX:XX:XX:XX:XX' option key 'XXXXXXXX' option macaddr 'XX:XX:XX:XX:XX:XX'

Interesting. It wasn't working for me on 0dcc36fc7dd, which is why I hacked that in. Kinda hard to see where it gets handled, and I don;t see any changes. surrounding that, though.

I had the same issue on the wan interface , and i was unable to solve it using luci .
Since i can access router over ssh shell , i created a script that changes automatically the mac address and i placed it on the /sbin folder and have it execution permissions .

My wan interface name is eth0.2 , so here it is the script for those that may need it .

#!/bin/sh
lstmc=$(ifconfig eth0.2 | grep "HWaddr" | awk '{print$5}')
perv=$(ifconfig eth0.2 | grep "inet addr" | awk '{print$2}' | cut -c 6-)
echo "Last ip was : $perv using Mac : $lstmc"
echo ""
echo "* - Turning wan interface off"
sleep 2
ifconfig eth0.2 down &> /dev/null
echo "* - Changing current MAC Address"
sleep 2
macchanger -A eth0.2 &> /dev/null
echo "* - Bringing Wan interface up"
sleep 2
ifconfig eth0.2 up
echo "* - Renewing IP"
sleep 2
dhclient eth0.2 &> /dev/null
nwmac=$(ifconfig eth0.2 | grep "HWaddr" | awk '{print$5}')
nwip=$(ifconfig eth0.2 | grep "inet addr" | awk '{print$2}' | cut -c 6-)
sleep 2
echo ""
echo "New ip is : $nwip using Mac : $nwmac"
echo ""
exit 1

for this to work you need to install the package macchanger on openwrt using opkg in the software menu .

uci set wireless.@wifi-iface[0].macaddr='xx:xx:xx:xx:xx:xx' uci commit wireless
This worked for me assuming I used lowercase letters in the MAC-address field.

Things have changed in 3 years. It works with uppercase as well.

Note if you set option bssid on a STA interface, it will connect only to an AP which has the exact MAC address matching the bssid option. That can be useful in point to point situations, but usually bssid should be left unset in case the AP gets replaced with one having a different MAC.

1 Like

What's the easy way to do this if you just want to change your MAC address one time in order to get a new IP?