MAC address randomization

Ubuntu Version

Ubuntu 24.04 LTS Flavors

Desktop Environment (if applicable)

MATE

Problem Description

Hello,
I’d like to randomize the MAC address. I know how to do this via Network Manager (GUI), but I’m not sure if that’s the best way for Ubuntu (which should use netplan). I recently discovered how to mask the MAC address, not manually on a network by network, but automatically via the configuration files in the /etc/NetworkManager/conf.d/ folder. For example:
myconfig.conf

[device-mac-randomization]
wifi.scan-rand-mac-address=yes

[connection-mac-randomization]
ethernet.cloned-mac-address=random
wifi.cloned-mac-address=random | stable

Now, if I set wifi.cloned-mac-address=random for certain wifi networks, I run into problems because authentication is based on the MAC address-password pair.
Is there any way to have a custom setting for a specific network?
Thank you

Just set it using nmcli.

$ nmcli connection modify Repeater_1EA7 wifi.cloned-mac-address random
$ 

which will store it in the netplan for this connection as

...
  wifis:
    NM-4538ce1f-5d1a-4748-8ace-4fe680fdec0b:
      renderer: NetworkManager
      match:
        name: "wlp2s0"
...
      macaddress: "random"
...

Or simply edit netplan definition directly. See https://netplan.readthedocs.io/en/stable/netplan-yaml/#properties-for-all-device-types

1 Like

If random is breaking authentication on that specific Wi-Fi, you don’t want to set random on that connection - that’s what is causing the issue in the first place!

Any setting on a specific connection profile will override your global /etc/NetworkManager/conf.d/ config. You have two options depending on what the network expects:

If the network uses a whitelist or MAC filtering, use your real hardware MAC:

nmcli connection modify "<your-wifi-name>" wifi.cloned-mac-address permanent

If it just needs the MAC not to change on every reconnect (like captive portals or DHCP lease bindings), use a stable randomized MAC:

nmcli connection modify "<your-wifi-name>" wifi.cloned-mac-address stable

With stable, NetworkManager creates a persistent randomized MAC tied to that specific SSID. It will always use the exact same MAC whenever you connect to that network, but your real hardware MAC stays hidden everywhere else…

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.