10

I bought the Miniature WiFi Module from ADAFruit (http://www.adafruit.com/products/814) and was wondering if it is possible to change the MAC address associated with it. I have tried using the following code:

sudo ifdown wlan0

sudo ifconfig wlan0 hw ether 00:11:22:33:44:55

sudo ifup wlan0

or

sudo ifdown wlan0

sudo macchanger -r wlan0

sudo ifup wlan0

or by adding a line in /etc/network/interfaces

hwaddress ether 00:11:22:33:44:55

When using lsusb the device shows up as "Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter". In /etc/hostapd/hostapd.conf, driver=rtl1871xdrv. I am running ISC DHCP Server.

The device works otherwise. I just want to be able to change the MAC address

  • This question has absolutely nothing to do with Raspberry Pi, please, choose another section of StackExchange for this type of inquiry. – lenik Oct 20 '13 at 10:39
  • 2
    ah, sorry. Was using Raspbian so looked like a good place to put it. I will find another location. – Joseph Oct 20 '13 at 16:31
  • Some drivers require the device to be up to do that. Try sudo ifconfig wlan0 up ; sudo macchanger -r wlan0 – M Noit Oct 21 '13 at 11:19
  • Unfortunately this doesn't work either. It has the error "Can't read permanent MAC: Operation not supported. Even though there is output for the NEW MAC, ifconfig shows the old MAC address. – Joseph Oct 22 '13 at 2:17
3

For "Raspbian GNU/Linux 8 (jessie)" (cat /etc/os-release), "Raspberry Pi reference 2017-06-21" (cat /etc/rpi-issue) (maybe also 2017-07-05) (thanks @Heinrich Ulbricht) and earlier see my answer here.

For "Raspbian GNU/Linux 9 (stretch)" (cat /etc/os-release), "Raspberry Pi reference 2017-08-16" (cat /etc/rpi-issue) (maybe also 2017-07-05) and later things changed. For example eth0 is now listed by systemd’s predictable network interface name enxb827ebxxxxxx. So my previous method via if-pre-up.d stopped working.

Instead you can use systemd and create the file /etc/systemd/network/00-mac.link as explained here:

[Match]
OriginalName=wlan0

[Link]
MACAddress=b8:27:eb:xx:xx:xx
NamePolicy=kernel database onboard slot path
  • 2
    Confirmed working with Raspian Stretch Lite. Kudos, Frank. – Josh Habdas Jun 2 '18 at 19:58
  • Confirming, too, that it works with Raspbian GNU/Linux 9. – typo Oct 21 '18 at 12:52
1

it is possible to change your mac address but this is a feature of the hardware and drivers.

i was successful using two wifi adapters TL-WN722N and the Alfa AWUS036H

however you should be aware that the Alfa AWUS036H has to be powered through a powered usb hub. if you try and run it directly off the pi you will get kernel panics.

service ifplugd stop

service wicd stop

ifconfig wlan0 down

macchanger -r wlan0 

ifconfig wlan0 up

good luck

1

I had the same issue - most of the standard ways of doing this didnt seem to work on the raspberry.

My situation was a bit different - I have a Raspberry PI B where the ethernet chip has died and so I used a usb-ethernet adpater. The adapter is maybe not the highest quality as it didnt have a unique MAC address. The adapter is assigned to eth1

I found the answer by enzorik here... http://www.raspberrypi.org/forums/viewtopic.php?f=6&t=5486, worked for me. Essentially...

Create a new script: sudo nano /etc/init.d/mac.sh

Paste into this script (settign your MAC address as required) ...

#! /bin/sh
ifconfig eth1 down hw ether 00:00:00:00:00:00
ifconfig eth1 up 

Make it executable: sudo chmod +x /etc/init.d/mac.sh

Then run: sudo update-rc.d /etc/init.d/mac.sh defaults

  • I would suggest to rather save mac.sh in /etc/network/if-pre-up.d/. This will avoid the usage of update-rc.d. See my answer below. – Frank Breitling Mar 18 '17 at 1:32
1

For the 8192cu driver you could do this by creating the file /etc/modprobe.d/8192cu.conf (the filename does not matter but it should have .conf extension) and adding a line that looks like:

options 8192cu rtw_initmac="XX:XX:XX:XX:XX:XX"

where "XX:XX:XX:XX:XX:XX" is the static MAC address

  • 1
    I have this exact same Model RTL8188CUS and this is the only solution that worked. Thank you! – Rucent88 Oct 23 '16 at 15:37
1

For "Raspbian GNU/Linux 9 (stretch)" (cat /etc/os-release), "Raspberry Pi reference 2017-08-16" (cat /etc/rpi-issue) (maybe also 2017-07-05) and later see my answer here.

For "Raspbian GNU/Linux 8 (jessie)" (cat /etc/os-release), "Raspberry Pi reference 2017-06-21" (cat /etc/rpi-issue) (thanks @Heinrich Ulbricht) (maybe also 2017-07-05) and earlier

you can add the following script to /etc/network/if-pre-up.d/mac:

#!/bin/sh

if [ "$IFACE" = wlan0 ]; then
    ip link set dev "$IFACE" address b8:27:eb:xx:xx:xx
fi

and make it executable with

chmod +x /etc/network/if-pre-up.d/mac

This should work with systemd and be more robust than the older update-rc.d method.

  • 1
    Tested successfully with "Raspbian GNU/Linux 8 (jessie)" (cat /etc/os-release), "Raspberry Pi reference 2017-06-21" (cat /etc/rpi-issue). (I'm documenting this to narrow down the release frame it works for since your second answer suggests it stops working at some point.) – Heinrich Ulbricht Nov 20 '17 at 14:45
  • 1
    Note this method will not work on Raspian Stretch. Thankfully Frank added a second answer and both are still technically correct. – Josh Habdas Jun 2 '18 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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