14

Recently, after I ran apt-get upgrade, my Pi 3 running Raspbian Jessie started using a random MAC address on eth0 after every reboot. I'm pretty sure this has something to do with the upgrade since I haven't messed with my network config in a long time.

My current /etc/network/interfaces file is as follows:

auto lo
iface lo inet loopback

iface eth0 inet auto

I tried appending the following line to it but to no avail:

    hwaddress ether xx:xx:xx:xx:xx:xx

As some people suggested in this thread I checked the serial no. in /proc/cpuinfo and it matches the static MAC address the Pi previously used.

Is there any way I could go back to having a static MAC address on my Pi?

mohak
  • 263
  • 1
  • 2
  • 9
  • What does uname -a output? – HeatfanJohn Jun 15 '17 at 17:10
  • I recently loaded Rasbian 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux and since I wanted to setup VNC connection I probably loaded other packages unknowingly. As suggested in the replies, I removed Network-Manager packages and the dynamic wlan0 MAC address is no longer an issue. Thanks for solving this thorny headache for my internet router was going crazy assigning a new IP to the Raspberry after every boot. El Zorro, Bordeaux, France – El Zorro Jun 20 '19 at 21:58
  • For anyone who wants a fixed MAC on wlan0 as opposed to eth0, see here. – cyqsimon Jun 04 '21 at 17:48

3 Answers3

15

Seems like it's a feature of network-manager...

I installed networkmanager and random mac shows up, so I uninstalled it and problems solved:

sudo apt-get remove network-manager
甘礼良
  • 151
  • 1
  • 2
  • 1
    thank you.. i confirm, network-manager is the cause for this behaviour. – ashishsony Oct 13 '19 at 08:04
  • I can also confirm this solved the problem for me – Michael Martin Nov 08 '19 at 17:09
  • 1
    Worked for me, but fortunately I didn't need the package. For those who do, you can configure it to stop this by querying the interw3b with keywords like "network-manager disable MAC address randomization". – Eliot Gillum Feb 26 '20 at 06:51
  • 11
    Couldn't add an answer, so to USE Network Manager without MAC randomization: create the file /etc/NetworkManager/conf.d/100-disable-wifi-mac-randomization.conf, then add this content on separate lines (without the slashes - those represent the line breaks): [connection]\wifi.mac-address-randomization=1\[device]\wifi.scan-rand-mac-address=no -- Save and reboot... This worked for me. – leanne Jul 04 '20 at 20:45
  • @leanne Seems like you may have enough reputation to add your brilliant answer now... – n1000 Jan 14 '21 at 22:16
13

Open a Terminal window and run:

sudo nano /boot/cmdline.txt

If in the file you see any mention of a MAC address remove it from the file. Then exit the file with saving.

To set a fixed MAC address run:

sudo nano /boot/config.txt

Add the following line if it does not already exist:

smsc95xx.macaddr=B8:AA:BC:DE:F0:12

Again, exit the file with saving. B8:AA:BC:DE:F0:12 is the MAC address.

Darth Vader
  • 4,206
  • 24
  • 45
  • 69
  • It worked, thanks! Any guesses as to what might have caused this behaviour? – mohak Jun 15 '17 at 19:00
  • 1
    I'm not sure to be honest with you, this isn't behavior I was aware of before today. Obviously something in the update process broke something. Having looked at the topic in other Pi forums it does seem to be an issue that has cropped up multiple times in the past and on various OS's as well. – Darth Vader Jun 15 '17 at 19:03
  • 1
    I haven't seen this myself, but have run across discussions on Ubuntu. The random MAC is a new standard to prevent tracking (on WiFi) when scannng for networks, but AFAIK should not affect DHCP request. Apple has been using this on iOS for a few years. – Milliways Jun 16 '17 at 00:07
  • On the raspberry fora (https://www.raspberrypi.org/forums/viewtopic.php?t=33252), it's suggested to place this in cmdline.txt rather that in config.txt. Is there a difference between the two? – Mr. White Sep 08 '18 at 22:36
  • For me, these actions didn't set the mac-address, but after the actions, the mac-address started to remain the same after rebooting. – arsdever Jan 04 '20 at 21:21
  • I once read that this only occurs with Raspberry Pi's with touch monitors. Wherever the connection is. – Micha93 Jul 05 '21 at 09:12
  • Did not worked for me. Probably of installed cockpit and network manager installed with it. – n.podbielski Nov 21 '21 at 15:34
1

As @leanne said in the comments, you can use this command to keep network-manager (needed for some features) but disable MAC Address Randomization:

printf "[connection]\nwifi.mac-address-randomization=1\n\n[device]\nwifi.scan-rand-mac-address=no\n" | sudo tee /etc/NetworkManager/conf.d/100-disable-wifi-mac-randomization.conf
Dan Chaltiel
  • 215
  • 3
  • 12