7

I was wondering about how to write a script for changing my default MAC address before enabling networking. It happens often, that the MAC address changes to default.

I would like to show the MAC address in conky (or any other graphical desktop interface). This script should also change the MAC address automatically if for any reason the default was restored.

Erling
  • 517

3 Answers3

8

NetworkManager itself can change a network interface MAC address and it will not be changed back to the default one while the connection is established.

Edit the network connection (NetworkManager indicator -> Edit connections -> Wireless tab -> Select a connection -> "Edit" button). In the "Wireless" tab you'll find a "Cloned MAC address" textbox. Type in the new MAC address it should use when the connection is established.

enter image description here

Eric Carvalho
  • 55,453
7

Just make script that will change mac address and make it run whenever you connect to network

#!/bin/sh
sudo ifconfig wlan0 down
sudo macchanger -a wlan0
sudo ifconfig wlan0 up

How to run cron job when network is up?

EDIT

@n00b, answers to your questions. So as I read here you can set macchanger to change MAC address automatically using

macchanger --mac=01:23:45:67:89:AB wlan0

And other question: "how to make it run automatically". So here it says you to add script to /etc/network/if-up.d/ and make it executable.

hingev
  • 6,684
0

I tried a number of different ways of making the Macchanger script work with Network Manager, but I never found a good one.

I tried the one proposed by Geoh, and apparently worked (it changes Mac Address of the interface every time you disconnect and reconnect), but even though Network Manager show you are connected to a network, you cannot connect anymore.

I tried to put the script in /etc/network/if-pre-up.d/ , /etc/network/if-down.d/ , /etc/network/if-post-down.d/ , but in that case it was just not working. I tried also without the ifconfig up/lines, but no success still.

I guess that is due to the fact Macchanger requires wireless card to be down, and Network Manager is kind of resetting some parameters of it every time you disconnect/connect.

For this reason I switched to Wicd, with this connection manager you simply save the script in /etc/rc.local

Good to know Network Manager now has "Cloned MAC address" option, though it is not the same as starting with a randomize Mac every boot (or even connection)

In the last part of this discussion, they propose workarounds, but I haven't tried them (https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/336736).

Cheers