13

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

Frank Breitling
  • 967
  • 1
  • 14
  • 28
Joseph
  • 131
  • 1
  • 1
  • 3
  • 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 02:17

5 Answers5

7

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
Frank Breitling
  • 967
  • 1
  • 14
  • 28
2

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

spiderplant0
  • 329
  • 3
  • 7
  • 16
2

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.

Frank Breitling
  • 967
  • 1
  • 14
  • 28
  • 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. – vhs Jun 02 '18 at 19:51
  • I just did the linked answer on Buster and it worked. Cheap Chinese Ethernet adapters came with the same MAC address. ~$1.20 for 3x USB and Ethernet though, can't complain too much. – YetAnotherRandomUser Nov 24 '19 at 19:56
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

jeremyforan
  • 131
  • 4
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

gypaetus
  • 111
  • 2