NEWMAC=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
ifconfig $1 ether $NEWMAC
ifconfig $1 down
ifconfig $1 up

I pass en0 or en1 as the sole argument to the script and run as sudo. When I do this, the MAC does change, however I cannot restore connectivity until I reboot and the new MAC is lost. Initially the interface displays no IP, but after a few minutes it displays an IP and claims to have DHCP information. However, I believe this is a cached data and not an actual renewal, as I cannot ping, load pages, or otherwise connect to the Internet.

I have appended this snippet with no improvement in results.

ipconfig set $1 BOOTP
ipconfig set $1 DHCP
  • I know it this was over three years ago, but did my solution solve your problem? If so, could you please mark it as the correct answer? Thanks! Dec 18, 2015 at 0:07

1 Answer 1


If you're on MacOSX 10.5 or later, at the beginning of your script, call sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z. Another thing you could do to improve this is to call the script itself with sudo instead of calling sudo multiple times within.

  • When I have sudo ifconfig $1 down before sudo ifconfig $1 ether $NEWMAC, I get this error: ifconfig: ioctl (SIOCAIFADDR): Device power is off. I've modified the script to require sudo when calling the script. May 27, 2012 at 23:13
  • Oh, my bad. I'll edit my answer. Did using sudo ifconfig set $1 DHCP work for you? May 27, 2012 at 23:19
  • Just tested it... results in ifconfig: interface set does not exist and the connection remains down. May 27, 2012 at 23:28
  • Oh, I messed up, and I edited my answer again. May 27, 2012 at 23:34
  • Oh, I think it's ipconfig and not ifconfig for this command, sorry. I get the two mixed up. Answer updated. May 27, 2012 at 23:39

You must log in to answer this question.

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