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.

1
  • 3
    Have you tried SpoofMAC (pip install SpoofMAC)? This still works on Yosemite for me.
    – L3viathan
    Commented Oct 21, 2014 at 12:27

8 Answers 8

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
2
  • 2
    This method worked for me. This needs to go higher on the answer list.
    – Riveascore
    Commented Dec 24, 2015 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
    Commented Aug 29, 2017 at 6: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
4
  • I tried this, and it still didn't work for me.
    – Riveascore
    Commented Dec 24, 2015 at 19:30
  • @FengHuo it worked for me, on 10.11.2 (though I used a different MAC address)
    – Mint
    Commented Jan 17, 2016 at 18:15
  • Works on 10.11.6 Commented Oct 18, 2016 at 13:51
  • 2
    You just made our family vacation much more enjoyable for the parents. Had to get the Apple TV onto the hotel's network behind a login screen and spoofing the MAC address worked a charm :) Commented Oct 30, 2016 at 4:44
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

3
  • 5
    Installing node.js to do something which can be done by simply running ifconfig seems kind of overkill...
    – nohillside
    Commented Sep 6, 2015 at 6: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 github.com/feross/SpoofMAC
    – Tyler
    Commented Sep 6, 2015 at 6: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
    Commented May 31, 2019 at 7: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
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`
-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.
1
  • 1
    How does this relate to the problem described in the question?
    – nohillside
    Commented Sep 20, 2015 at 5:05
-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 :)

1
  • What makes your answer smarter? What does smarter mean in this context? Commented Mar 15, 2018 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .