1

Is it possible to spoof my MAC address when connecting to a specific WiFi network only?

I thought of using a script in /etc/NetworkManager/dispatcher.d/ that would change my device's MAC address before connecting and then change it back to the hardware default when disconnected, but all methods of changing the MAC address I know of require the "NetworkManager" service to be stopped and restarted which obviously can't happen when the script is run.

Is there any way of detecting a change in network connection outside of the "NetworkManager" actions? I am asking for Fedora specifically, but I'm sure the solution would be general for Linux.

3

1 Answer 1

3

Changing the MAC address does not require restarting NetworkManager if you tell NetworkManager to change it. To do this, specify 802-11-wireless.cloned-mac-address in the NetworkManager profile:

nmcli con modify "My Little Wifi" wifi.cloned-mac-address 12:34:56:AB:CD:EF
nmcli con up "My Little Wifi"
  # (reconnect to apply)

(The default for this parameter is permanent which uses the hardware address. You can also set it to preserve to use the address set by external tools.)

Is there any way of detecting a change in network connection outside of the "NetworkManager" actions? I am asking for Fedora specifically, but I'm sure the solution would be general for Linux.

No, it wouldn't be. Linux can generically tell you what SSID it's currently associated to, but that's too late – the change needs be done before userspace tells the kernel to associate with a specific network.

  1. To change the interface's MAC address, it must be set to "down" (disabled), otherwise the OS will refuse the change.
  2. Wi-Fi associations are between peers identified by their MAC address. If you somehow change the address while associated, the AP/router won't recognize you anymore and the client has to reassociate.

So you need to hook into the distro-specific network management program. Admittedly, most of them (including NetworkManager) use the same wpa_supplicant software under the hood, but 1) it's often sent configuration from different sources in different ways, and 2) it only has an option to randomize the MAC address, but not to use a specific one.

1
  • The first part did exactly what I needed. Mar 4, 2019 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.