Randomizing (spoofing) MAC address in Fedora 16 linux

Update: The instructions for Fedora 19 are here.

Update:  This stopped working when I upgraded to Fedora 17 — it seems NetworkManager gets turned on earlier in the boot sequence.  My  fix for Fedora 17 is here.

I like to randomize my MAC address when I boot my laptop, mostly as a basic protective measure for a box I use when I travel.  There are a number of good posts for doing this in Ubuntu, but I didn’t see much for Fedora that  didn’t require turning off the Network Manager.  So, I’ve been poking around.  Right now, I’m playing with Fedora 16 beta.


Turns out it’s not that hard.    It *seems* (though this is from a rather scattershot attempt at a solution) that you have to change the hardware address *before* any networking software starts — be it network intialization, network manager, whatever.  Of course, in linux, setting the hw address is trivial using the ifconfig command.  For instance, for wlan0, you might use

ifconfig wlan0 down

ifconfig wlan0 hw ether 11:22:33:44:55:66

ifconfig wlan0 up

Personally, though, I don’t like this method because I don’t know anything about how MAC addresses are assigned to companies, etc., and I have had problems with public connections using truly random numbers.  Happily, there is the wonderful progam called “macchanger” available from most repositories that will provide a more intelligent change.

So, the question becomes *when* to run it.  There are basically three options:  before networking gets started altogether, after networking gets going, but before NetworkManager is invoked, or after NetworkManager is invoked.

The last one, just runining macchanger as root, just doesn’t work. I get the error:

%macchanger -a wlan0
Current MAC: 00:00:41:04:21:48 (Ice Corporation)
ERROR: Can’t change MAC: interface up or not permission: Device or resource busy.

So, I tried putting it in  as a script in /etc/NetworkManager/dispatcher.d as an early script.  Same error.

Finally, I said screw it, and created a script in /etc/init.d called macchangerd that looks something like:



start() {
echo "in macchangerd"
macchanger -a wlan0

# See how we were called.
case "$1" in
echo $"Usage: $prog {start}"
exit 1



Make sure that the script is executable.  Also, replace wlan0 with the name of the wireless device on your machine — it may be something different.

Then, I just added a line to /etc/rc.d/rc3.d:

ln -s /etc/init.d/macchangerd /etc/rc.d/rc3.d/S04macchangerd

I made it 04 in order to put it before any networking stuff.


And it seems to work.  My wireless device (wlan0) comes up with a different MAC address every time I boot,and I can connect — at least to my home network.

Update:  I’ve noticed a few hits each day on this post from folk searching this topic on search engines.  If anybody out there gives this a try on their box, give some feedback in the comment to let folk know that it worked for you, or if not, what went wrong.  Thanks!