36

I usually changed my MAC address with the following commands:

# Get a New MAC Address
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
# Changing the MAC Address
sudo ifconfig en0 ether d4:33:a3:ed:f2:12

When I enter:

ifconfig en0 |grep ether

I still get the old MAC address :( - Who can help? I would love to have a script or system to automatically change it on system boot.

Dillon
  • 2,391
Lupo
  • 1,259

8 Answers8

38

One possible problem is that randomly generated MACs will fail half the time. The first byte of a MAC address needs to be even (e.g. end in 0, 2, 4, 6, 8, A, C, E).

So, for example, 3b:92:22:cf:55:7e wouldn't work because '3b' is odd. See Wikipedia's MAC address article for the details (even = unicast, odd = multicast).

To avoid this problem, you can slightly edit your random-MAC sed command to force the second nibble to 0.

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

Combining this with hrbrmstr's answer worked for me:

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --disassociate
sudo ifconfig en0 ether $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/./0/2; s/.$//')
networksetup -detectnewhardware
user137369
  • 1,568
seren
  • 1,068
  • 2
    This method worked for me. This needs to go higher on the answer list. – Riveascore Dec 24 '15 at 19:33
  • One thing to make that a wee bit shorter:

    sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z; sudo ifconfig en0 ether a0$(openssl rand -hex 5 | sed 's/\(..\)/:\1/g'); networksetup -detectnewhardware

    It does make it a little less random.

    – Kevin Lyda Aug 29 '17 at 06:21
27

You need to disassociate the device before changing the MAC address. For en0, it will be:

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
sudo ifconfig en0 ether d4:33:a3:ed:f2:12
networksetup -detectnewhardware
hrbrmstr
  • 379
7

Ferros made a sweet node tool to do just this https://github.com/feross/spoof

He has a Python version as well https://github.com/feross/SpoofMAC

  • 5
    Installing node.js to do something which can be done by simply running ifconfig seems kind of overkill... – nohillside Sep 06 '15 at 06:20
  • 2
    Kind of goes without saying that it's a solution for node users. He also has a Python (which comes pre-installed on Macs) version https://github.com/feross/SpoofMAC – Tyler Buchea Sep 06 '15 at 06:27
  • 1
    ifconfig isn't cross-platform; that "node overkill" works on Windows, Linux and macOS. Plus $ spoof reset does the opposite, in 2 words. – fregante May 31 '19 at 07:42
4

This command works fine for me, the random script have I taken from this answer: https://serverfault.com/a/299564 from MadHatter.

sudo ifconfig en0 ether $(perl -e 'for ($i=0;$i<5;$i++){@m[$i]=int(rand(256));} printf "02:%X:%X:%X:%X:%X\n",@m;') && sudo ifconfig en0 down && sudo ifconfig en0 up
Tukan3
  • 365
1

Use this

sudo ifconfig en0 lladdr d4:33:a3:ed:f2:12

See the manual page of ifconfig

man ifconfig

0

Here's my contribution to change your MAC address: https://gist.github.com/vinyll/b511159cce2d25edafe78403749088ca

#/bin/sh

# Instructions:
# 1. Copy this script locally and run the following `chmod +x mac-address-spoofer.sh`
# 2. Later, run the following: `./mac-address.spoofer.sh` and see your MAC address changing.

echo "origin MAC address: " `sudo ifconfig en0 ether | grep ether`
sudo ifconfig en0 ether `openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
echo "new MAC address: " `sudo ifconfig en0 ether | grep ether`
vinyll
  • 111
-1

This works!

Steps:

  1. Get the MAC address of your Apple TV and write it down. It's found in the Network Settings.

  2. Get the MAC address of your MacBook (Yosemite OS version). Type "ifconfig" in a terminal window. It will be in the "En0" section.

  3. Cut/Paste the following (replacing the X's with your Apple TV MAC address) into a teminal window:

change MAC OSX to the Apple TV MAC

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z

sudo ifconfig en0 ether XX:XX:XX:XX:XX:XX

networksetup -detectnewhardware

  1. Enter your password if prompted and repeat step 3, if necessary**

  2. Reconnect to the hotel wireless with your MAC (not Apple TV) and accept the conditions of service.

  3. Cut/paste the following into the terminal window (replace the Y's with your MAC OSX MAC address)

change MAC address back to original

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z

sudo ifconfig en0 ether YY:YY:YY:YY:YY:YY

networksetup -detectnewhardware

  1. Connect to the hotel wireless with your Apple TV.
Mark
  • 1
-1
sudo ifconfig en0 ether `openssl rand -hex 5|perl -nE '$s.=join":",/../g}{say"02:$s"'`&& sudo ifconfig en0 down && sudo ifconfig en0 up

My is much smarter :)

Mantovani
  • 109
  • 1