Skip to content
Tags

Start your computer with a random mac address

August 2, 2010

Step 1: Generate a random mac address:

MAC=`echo -n 00; hexdump -n 5 -v -e '/1 ":%02X"' /dev/urandom;`

Step 2 : Bring up the network card with the mac address:

(Here I’m using my wireless card so the interface would be wlan0 but the command works for pretty much any interface).

ifconfig wlan0 down
ifconfig wlan0 hw ether $MAC
ifconfig wlan0 up

That will bring up your network interface with the new mac address.

For those of you that are using Network Manager (nm-applet on your gnome-desktop), you will have to restart the network manager service reconnect to your wireless network.

Ubuntu 9.10 and higher :

service network-manager restart

Ubuntu 9.04 and lower :

/etc/init.d/network-manager restart

Fedora / CentOS :

service NetworkManager restart

Now, to get that setup on boot, add the commands to /etc/rc.local , and you’ll have something like this :


MAC=`echo -n 00; hexdump -n 5 -v -e '/1 ":%02X"' /dev/urandom;`

ifconfig wlan0 down
ifconfig wlan0 hw ether $MAC
ifconfig wlan0 up

service network-manager stop
service network-manager start

You can modify that script to fit your Linux distribution.

About these ads

From → Linux Tutorials

10 Comments
  1. johndoe permalink

    Any tips on how to do this in Windows or OSX?

    • Shreyas Siravara permalink

      OSX should be the same, windows I do not know about. The ifconfig command for OSX has a syntax that is just a little bit different.

    • Shreyas Siravara permalink

      Windows : http://lantoolbox.com/articles/find-and-change-spoof-your-mac-address-in-windows-xp/

  2. sudo ifconfig en1 ether ‘mac address’

  3. Alternative:
    Use “macchanger tool” with “-r” option (set fully random MAC)
    sudo macchanger -r wlan0

  4. Tobias permalink

    echo -n 00; hexdump -n 5 -v -e ‘/1 “:%02X”‘ /dev/urandom

  5. soldack permalink

    You should always set the local bit if you are going to do a random MAC address. It should start with 02.

    • Bill Biller permalink

      Actually.. 02 would set the global bit, the local bit would make the mac address start with ’00′. This is how IEEE defines the MAC address, during IPv6 address autoconfiguration that bit is flipped.. so the ’00′ in the hardware MAC becomes ’02′ in the EUI64.

      • soldack permalink

        See http://en.wikipedia.org/wiki/MAC_address and check out the picture, http://en.wikipedia.org/wiki/File:MAC-48_Address.svg . In the breakout of the OUI, b2 is the global/local bit. 0 means global OUI enforced and 1 means locally administered.

  6. Daniel permalink

    I have found that DHCP fails after enabling this. I’ve watched the transaction in Wireshark and the Debian system requests an IP and the DHCP server responds but for some reason the Debian system doesn’t see it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: