One of the oddities of Apple’s Mac OS X platform is that some things that should be easy are obtusely difficult, and remarkably so. Changing the hostname of a Mac OS X Server is one good example. Another is changing the “Ethernet ID” (aka. MAC address, aka. link-level address) of a network interface card.
This should be really simple, as the correct command line is plain as day (where the string of colon-separated 00’s is your preferred MAC address):
sudo ifconfig en1 lladdr 00:00:00:00:00:00
There are numerous blog posts all over the ‘net that tell you this time and again, but each one seems to have comments from users complaining that it doesn’t work on their system. I ran into a similar problem not long ago when my MacBook Pro didn’t do what I expected. Just like others, whenever I tried to run the above command, nothing seemed to happen:
ifconfig | grep ether # Determine current MAC addresses sudo ifconfig en1 lladdr 00:00:00:00:00:00 # Try changing MAC address for en1 (usually Airport) ifconfig | grep ether # Confirm change; but uh-oh! Output is the same as before! Why?
Here’s how I fixed this problem.
The thing to know is that there seem to be a number of conditions that will prevent Mac OS X from successfully changing a NIC’s MAC address. Some are obvious and some are not. As far as I can tell, these conditions are:
- having the interface “down” (i.e., if you’ve recently run
ifconfig en0 downor an equivalent),
- being associated with (i.e., connected to) a Wi-Fi network with your Airport card,
- having the System Preferences application running,
- forgetting to “unstick” the current system configuration set.
It’s the last one that bit me. Mac OS X has a feature called “system configuration sets” or “locations,” as it’s termed in much of the GUI. These can be accessed via the Network pane in System Preferences, or via the
scselect command from Terminal; it’s that
scselect command which offers the key to changing a Mac’s MAC address.
On my MacBook Pro (which, for the record and if it matters, is running Mac OS X 10.6.7), I need to do all of the following before running
ifconfig, as shown above:
- If I’m changing my Airport card’s MAC address, I need to disassociate from any network. (This can most easily be done by invoking
airport -zfrom Terminal. If you don’t have this command, see my tips on where to find
- Quit System Preferences if it’s open.
- Tell the operating system to “delay changing the system’s ‘location’ until the next system boot” by running:
According to the
man page for
scselect provides access to the system configuration sets, commonly referred to as “locations”. When invoked with no arguments, scselect displays the names and associated identifiers for each defined “location” and indicates which is currently active. scselect also allows the user to select or change the active “location” by specifying its name or identifier. Changing the “location” causes an immediate system re-configuration, unless the -n option is supplied.
-n Delay changing the system’s “location” until the next system boot (or the next time that the system configuration preferences are changed).
Once I perform the above rigmarole, I can then change my MAC address without issue. But I have to be ludicrously careful. As soon as I open the Network System Preferences pane or otherwise do something to change the system configuration preferences, I have to run through that rigmarole again before changing my MAC address will work as expected.