Random MAC address generator

Nov 10, 2010 - 13 Comments

Do you want to generate a random MAC address? No problem with this neat tip sent in by one of our readers, just paste the following into the command line:

openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'

The hexadecimal output will be the generated MAC address, and will look something like this: 07:e0:17:8f:11:2f

This is pretty helpful if you need to create a new MAC address for something like your router or cable modem. Of course you can also spoof your MAC address rather easily in Mac OS X if you want to use one of the generated addresses for that purpose too.

This command has been tested to work in Linux and Mac OS X.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line


» Comments RSS Feed

  1. first says:

    I always just concoct random hex strings in my head, this is a bit less brain work so thanks

  2. Matt says:

    You need to be careful that this does not generate multicast mac addresses, as these are technically illegal as source macs. The strict definition of a multicast mac address is one where the least significant bit of the first byte is set to 1. So if the first octet’s LSB is 1 (01, 03,05, a1, etc) you technically have a multicast mac source. See http://en.wikipedia.org/wiki/MAC_address.

    Using multicast src macs might not cause immediate connectivity problems, but certainly has implications for switches learning the mac address preventing unicast flooding, and routers allowing arp to resolve.

    Cisco, for example, will not allow mac learning if the source is non-unicast, and Cisco routers will not install arp entries for multicast macs to unicast ip addresses.

    I think you need to rethink this post taking into consideration these consequences.

  3. Ben Stoltz says:

    ruby -e ‘print (“%02x”%((rand*64).to_i*4|2))+(0..4).inject(“”){|s,x|s+”:%02x”%(rand*256).to_i} + “\n”‘

    The result is a locally administered, non-multicast MAC address.

  4. [...] note that the MAC address above is not the real one of my drives but a generated fake, for the sake of understanding the [...]

  5. [...] that value returned from ifconfig to another hex value in the format of aa:bb:cc:dd:ee:ff. You can generate a random one if need [...]

  6. waffletower says:

    The ruby snippet was broken. I don’t know ruby. I love perl though:

    perl -e ‘printf “\n%02x:”, $x=(int(rand(128))*2); for($i=0;$i<4;$i++){printf "%02x:",$x=int(rand(256));}printf "%02x", $x=int(rand(256));printf"\n\n";'

  7. [...] shown you how to generate MAC addresses randomly and then how to go about changing a MAC address in OS X Lion and OS X Mountain Lion, but why have [...]

  8. Holger says:

    And with bash calculation use this:

    printf ‘%02x:’ $(( 0x$(od /dev/urandom -N1 -t x1 -An | cut -c 2-) & 0xFE | 0×02)); \
    od /dev/urandom -N5 -t x1 -An | cut -c 2- | sed ‘s/ /:/g’

  9. Hidayat says:

    How to change mac address in nokia n8?

  10. Hidayat says:

    I am change mn my mac address but my computer not conectinge in conecting other wi-fi.in conctinge other computer this wi-fi.
    in my password is carickd.

  11. x says:

    The one from Holger is correct:
    printf ‘%02x:’ $(( 0x$(od /dev/urandom -N1 -t x1 -An | cut -c 2-) & 0xFE | 0×02)) ; od /dev/urandom -N5 -t x1 -An | cut -c 2- | sed ‘s/ /:/g’

Leave a Reply


Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates