PDA

View Full Version : How to randomize Wi-Fi device MAC address on Debian 11?



Fli
03-28-2024, 10:57 AM
I am trying to randomize Wi-Fi device MAC address on Debian 11.

A)
$ nmcli device|grep wif
first string of the output is the wifi device name (it is also displayed in "nmcli device wifi" output)

$ sudo macchanger -r WifiDeviceNameHere

Current MAC: 00:..:..:..:..:.. (wifi vendor name)
Permanent MAC: 00:..:..:..:..:.. (wifi vendor name)
[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy

It not helped to disable networking.

I could define new MAC under system tray, network icon, connections editor, wifi tab. Apparently the MAC was changed. But I assume no randomization on each restart.

$ su
$ crontab -e
add new line:
@reboot macchanger -r WifiDeviceNameHere

B)
If MAC is not preserved, someone mentioned:
nano /etc/NetworkManager/NetworkManager.conf

if it contains a connection section, leave first line and add next two lines:

[connection]
ethernet.cloned-mac-address=preserve

If that does not work either, then maybe do:
$ cd /etc/NetworkManager/system-connections/;ls
and then edit appropriate wifi interface file:
$ nano filename
it should contain:

[wifi]
cloned-mac-address=.....addresshere....
mac-address-blacklist=
mode=infrastructure
ssid=mynetworkname

There is a script (https://web.archive.org/web/20231001023727/https://feldspaten.org/2021/12/31/Update_MAC_NetworkManager/) which takes the new MAC address (e.g. 00:aa:bb:cc:dd:ee) as argument and then changes all system-connections files to use this new MAC address instead.

I am not yet sure how to generate random valid MAC address.

C)
another thing to try:
$ cd /usr/lib/systemd/network/;ls
edit appropriate file (or make new one), maybe:
$ nano 99-default.link
making sure that the [link] section contains:

[Link]
MACAddressPolicy=random
$ systemd-analyze # is this working to verify the configuration?



Do you know how to randomize MAC better and more simple?