Random MAC Address Generator

Nov 10, 2010 - 14 Comments

Do you want to generate a random MAC address? That’s no problem with this neat openssl tip sent in by one of our readers, and you can run the command once or multiple times to generate a randomized MAC address instantly on each execution.

To get started, jump to your terminal or command line window, and paste the following syntax into the command line to generate a randomized MAC address:

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

Be sure that command syntax is pasted onto a single line. The advantage to this trick is that it’s fairly simple, short, sweet, and doesn’t require any third party utilities or scripts, it works in OS X and Linux as is.

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

If you want to generate a new address, just hit the UP arrow on the keyboard, then hit RETURN again, this will re-execute the same command in just about any modern shell. Unless you know what you’re doing, you probably won’t want to edit the command syntax itself otherwise you could wind up generating inaccurate or incomplete hexadecimal that may not match a potential MAC address. Keep it simple, stick with the following syntax if you’re not sure:

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

If you plan on using this often, consider setting up an alias in your .bash_profile or .profile so that you don’t have to type out the entire command string, simply placing an alias can be done like so:

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

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, with virtually every version. The only requirement is that the command line has openssl and sed.

Terminal in OS X

Thanks to Akili for sending in this excellent little trick, if you know of any other ways to quickly generate a randomized MAC address, just let us know in the comments!

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

14 Comments

» 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 | 0x02)); \
    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 | 0x02)) ; 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