How to Enable MAC Address Randomization with NetworkManager

Boost your anonymity with just a few simple commands by randomizing your MAC address using NetworkManager and avoid hostname leaks during DHCP.

In the digital age, privacy is a paramount concern for many users. One often overlooked aspect of digital privacy is the Media Access Control (MAC) address—a unique identifier assigned to network interfaces. In Debian 12, NetworkManager offers a robust feature: MAC address randomization. This functionality enhances user privacy by preventing tracking based on a device’s MAC address.​


Understanding MAC Address Randomization

MAC addresses serve as unique identifiers for network devices, facilitating communication within local networks. However, this uniqueness can be exploited to track devices across different networks, posing a privacy risk. MAC address randomization mitigates this risk by generating alternative MAC addresses, making it more challenging for third parties to monitor a device’s network activity.​


Configuring MAC Address Randomization in Debian 12

Debian 12’s NetworkManager allows users to enable MAC address randomization globally or for specific connections. Here’s how to configure both:​

1. Global Configuration

To apply MAC address randomization across all Wi-Fi connections:​

  • Create a Configuration File: Open a terminal and execute:
sudo nano /etc/NetworkManager/conf.d/00-macrandomize.conf
  • Insert the Following Settings:
[device]
wifi.scan-rand-mac-address=yes

[connection]
wifi.cloned-mac-address=stable
ethernet.cloned-mac-address=stable
  • wifi.scan-rand-mac-address=yes: Enables MAC randomization during Wi-Fi network scans.​
  • wifi.cloned-mac-address=stable: Assigns a consistent, randomized MAC address for each Wi-Fi network, ensuring the same address is used upon reconnecting to the same network.​
  • ethernet.cloned-mac-address=stable: Applies similar behavior for wired Ethernet connections.​

Note: Setting cloned-mac-address to random instead of stable will generate a new MAC address each time you connect to a network, which may cause issues with networks that rely on consistent MAC addresses for identification.​

  • Restart NetworkManager: Apply the changes by restarting NetworkManager:
sudo systemctl restart NetworkManager

2. Per-Connection Configuration

To enable MAC randomization for individual connections:​

  • List Existing Connections:
nmcli connection show
  • Modify a Specific Connection:

Replace your-connection-name with the desired connection’s name:

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

For a new MAC address upon each connection:​

nmcli connection modify your-connection-name wifi.cloned-mac-address random
  • Reactivate the Connection:
nmcli connection down your-connection-name
nmcli connection up your-connection-name

Verifying the Configuration

To confirm that MAC randomization is active:

ip link show

Locate your network interface (e.g., wlan0) and check the link/ether field to view the current MAC address.​

Considerations

  • Network Compatibility: Some networks utilize MAC addresses for identification or access control. Ensure that MAC randomization doesn’t interfere with your ability to connect to such networks.​
  • Hostname Disclosure: Even with MAC randomization enabled, your device’s hostname might still be disclosed during DHCP requests. To prevent this, you can edit the DHCP client configuration:
sudo nano /etc/dhcp/dhclient.conf

Locate the line:​

send host-name = gethostname();

Comment it out by adding a # at the beginning:​

#send host-name = gethostname();

Save and close the file, then restart the networking service or reboot your system to apply the changes.​


Conclusion

By enabling MAC address randomization in Debian 12’s NetworkManager, you take a significant step toward enhancing your digital privacy. Whether applying this feature globally or tailoring it to specific connections, Debian 12 provides the flexibility to safeguard your network identity effectively.​


References

Stay In Touch.

Let's Get Creative.