Spoof (anonymize) your MAC address and hostname automatically at boot on macOS

macbook

Unfortunately this guide does not work on Macs equipped with the new T2 chip running macOS Mojave. If that’s your case, please upgrade to Catalina.

Every network adapter (the physical hardware used to connect to Wi-Fi access points) has its very own (and very unique) identifier called a MAC address. It looks something like this: 00:0C:29:5B:14:B3.

Want to know yours? Run the following command.

ifconfig en0 | grep ether | awk '{print $2}'

This MAC address is always the same by default and can be used to identify you personally (well, your device) when you go from one place to another.

Have you ever wondered how Wi-Fi networks that offer the first 30 minutes for free know who you are? You might have tried creating another account to get additional minutes, but that didn’t work right? That’s because your MAC address is used to identify your device.

Guide

Step 1: create /usr/local/sbin folder

sudo mkdir /usr/local/sbin
sudo chown $(whoami):admin /usr/local/sbin/

Step 2: create spoof.sh script

Pro tip 1: when copy/pasting commands that start with cat << "EOF", select all lines (from cat << "EOF" to EOF) at once as they are part of the same (single) command

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

set -e

export LC_CTYPE=C

dirname=`dirname "${BASH_SOURCE}"`

# Spoof computer name
model_name=`system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//'`
first_name=`sed "$(jot -r 1 1 2048)q;d" $dirname/first_names.txt | sed -e 's/[^a-zA-Z]//g'`
computer_name=`echo "$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"
echo "Spoofed hostname to $host_name"

# Spoof MAC address of en0 interface
mac_address_prefix=`sed "$(jot -r 1 1 768)q;d" $dirname/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"
echo "Spoofed MAC address of en0 interface to $mac_address"
EOF

Ok, a lot is happening here. Let’s break it down into reviewable pieces.

set -e

Exit on error

export LC_CTYPE=C

Fix sed: RE error: illegal byte sequence sed error

dirname=`dirname "${BASH_SOURCE}"`

Set variable dirname to path of spoof.sh

model_name=`system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//'`

Set variable model_name to the model of your Mac

first_name=`sed "$(jot -r 1 1 2048)q;d" $dirname/first_names.txt | sed -e 's/[^a-zA-Z]//g'`

Set variable first_name to random first name found in first_names.txt

computer_name=`echo "$first_name’s $model_name"`
host_name=`echo $computer_name | sed -e 's/’//g' | sed -e 's/ /-/g'`

Set variables computer_name and host_name using values from variables first_name, model_name and computer_name

sudo scutil --set ComputerName "$computer_name"
sudo scutil --set LocalHostName "$host_name"
sudo scutil --set HostName "$host_name"
echo "Spoofed hostname to $host_name"

Set ComputerName, LocalHostName and HostName using scutil and echo spoofed computer name

mac_address_prefix=`sed "$(jot -r 1 1 768)q;d" $dirname/mac_address_prefixes.txt | sed -e 's/[^A-F0-9:]//g'`

Set variable mac_address_prefix to random Apple MAC address prefix found in mac_address_prefixes.txt

mac_address_suffix=`openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//'`

Set variable mac_address_suffix to random value genereated by OpenSSL

mac_address=`echo "$mac_address_prefix:$mac_address_suffix" | awk '{print toupper($0)}'`

Set variable mac_address using values from variables mac_address_prefix and mac_address_suffix and convert to upper case

sudo ifconfig en0 ether "$mac_address"
echo "Spoofed MAC address of en0 interface to $mac_address"x

Set spoofed MAC address using ifconfig and echo spoofed MAC address

Step 3: make spoof.sh executable

chmod +x /usr/local/sbin/spoof.sh

Step 4: 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 https://sunknudsen.com/static/media/privacy-guides/spoof-anonymize-your-mac-address-and-hostname-automatically-at-boot-on-macos/first_names.txt

Step 5: download mac_address_prefixes.txt

This list includes 768 Apple MAC address prefixes.

curl -o /usr/local/sbin/mac_address_prefixes.txt https://sunknudsen.com/static/media/privacy-guides/spoof-anonymize-your-mac-address-and-hostname-automatically-at-boot-on-macos/mac_address_prefixes.txt

Step 6: create local.spoof.plist launch daemon

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

cat << "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist > /dev/null
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>spoof.sh</string>

        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/sbin/spoof.sh</string>
        </array>

        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>
EOF

Step 7: 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"?

👍

Hope you enjoyed this guide.

Contributors:Sun KnudsenSun Knudsen

Wish to contribute? Please submit an issue or a pull request.
This website is not tracking you. PGP public key fingerprint: C4FB DDC1 6A26 2672 920D  0A0F C132 3A37 7DE1 4C8B