Last updated Jul 21, 2021

Published under MIT licence

How to spoof MAC address and hostname automatically at boot on macOS

Heads-up: unfortunately this guide doesn’t work on Macs equipped with T2 chips running macOS Mojave. If that’s your case, consider upgrading to Catalina.

Heads-up: unfortunately this guide doesn’t work on Macs equipped with M1 processors (see issue).


  • When copy/pasting commands that start with $, strip out $ as this character is not part of the command
  • When copy/pasting commands that start with cat << "EOF", select all lines at once (from cat << "EOF" to EOF inclusively) as they are part of the same (single) command


Step 1: create /usr/local/sbin directory

sudo mkdir -p /usr/local/sbin
sudo chown ${USER}:admin /usr/local/sbin

Step 2: add /usr/local/sbin directory to PATH environment variable

Heads-up: run echo $SHELL to find default shell.

Bash (/bin/bash)

echo 'export PATH=$PATH:/usr/local/sbin' >> ~/.bashrc
source ~/.bashrc

Z Shell (/bin/zsh)

echo 'export PATH=$PATH:/usr/local/sbin' >> ~/.zshrc
source ~/.zshrc

Step 3: create script

cat << "EOF" > /usr/local/sbin/
#! /bin/sh

set -e
set -o pipefail

export LC_CTYPE=C

basedir=$(dirname "$0")

# Spoof computer name
first_name=$(sed "$(jot -r 1 1 2048)q;d" $basedir/first-names.txt | sed -e 's/[^a-zA-Z]//g')
model_name=$(system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//')
computer_name="$first_name’s $model_name"
host_name=$(echo $computer_name | sed -e 's/’//g' | sed -e 's/ /-/g')
sudo scutil --set ComputerName "$computer_name"
sudo scutil --set LocalHostName "$host_name"
sudo scutil --set HostName "$host_name"
printf "%s\n" "Spoofed hostname to $host_name"

# Spoof MAC address of en0 interface
mac_address_prefix=$(sed "$(jot -r 1 1 768)q;d" $basedir/mac-address-prefixes.txt | sed -e 's/[^A-F0-9:]//g')
mac_address_suffix=$(openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//')
mac_address=$(echo "$mac_address_prefix:$mac_address_suffix" | awk '{print toupper($0)}')
sudo ifconfig en0 ether "$mac_address"
printf "%s\n" "Spoofed MAC address of en0 interface to $mac_address"

Step 4: make executable

chmod +x /usr/local/sbin/

Step 5: download first-names.txt

This list includes the top 2048 most popular baby names from the USA Social Security Administration.

curl -o /usr/local/sbin/first-names.txt

Step 6: download mac-address-prefixes.txt

This list includes 768 Apple MAC address prefixes.

curl -o /usr/local/sbin/mac-address-prefixes.txt

Step 7: create local.spoof.plist launch daemon

This step is responsible for running every time your Mac boots.

cat << "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">



Step 8: reboot and confirm hostname and MAC address have been spoofed

# Spoofed hostname
$ scutil --get HostName

# Spoofed MAC address
$ ifconfig en0 | grep ether | awk '{print $2}'

# Hardware MAC address
$ networksetup -listallhardwareports | awk -v RS= '/en0/{print $NF}'

“Spoofed hostname” is random and “Spoofed MAC address” doesn’t match “Hardware MAC address”?


Want things back the way they were before following this guide? No problem!

Step 1: set computer name, local hostname and hostname

Replace John with a name to your liking.

sudo scutil --set ComputerName "John’s MacBook Pro"
sudo scutil --set LocalHostName "Johns-MacBook-Pro"
sudo scutil --set HostName "Johns-MacBook-Pro"

Step 2: set MAC address to default value

Given MAC address spoofing is ephemeral, deleting the /Library/LaunchDaemons/local.spoof.plist launch daemon and rebooting will reset your MAC address to its default value.

sudo rm /Library/LaunchDaemons/local.spoof.plist

Step 3: delete script and datasets

rm /usr/local/sbin/
rm /usr/local/sbin/first-names.txt
rm /usr/local/sbin/mac-address-prefixes.txt


Contributors:Sun KnudsenSun Knudsen
Reviewers:Be the first

Wish to contribute or need help? Read the docs.
This website is not tracking you. PGP public key fingerprint: C4FB DDC1 6A26 2672 920D  0A0F C132 3A37 7DE1 4C8B