2020-06-18 10:59:51 -04:00
<!--
Title: How to spoof (anonymize) your MAC address and hostname automatically at boot on macOS
Description: Learn how to spoof (anonymize) your MAC address and hostname automatically at boot on macOS.
Author: Sun Knudsen < https: / / github . com / sunknudsen >
Contributors: Sun Knudsen < https: / / github . com / sunknudsen >
2020-09-10 10:07:07 -04:00
Reviewers:
2020-06-18 10:59:51 -04:00
Publication date: 2020-05-19T00:00:00.000Z
-->
# How to spoof (anonymize) your MAC address and hostname automatically at boot on macOS
2020-08-02 06:55:08 -04:00
[](https://www.youtube.com/watch?v=ASXANpr_zX8 "How to spoof (anonymize) your MAC address and hostname automatically at boot on macOS - YouTube")
2020-06-18 10:59:51 -04:00
> Heads up: unfortunately this guide does not work on Macs equipped with the new T2 chip running macOS Mojave. If that’ s your case, please consider upgrading to Catalina.
2020-08-25 07:40:01 -04:00
## Caveats
- 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
## Guide
2020-08-10 19:35:31 -04:00
### Step 1: create `/usr/local/sbin` folder
2020-06-18 10:59:51 -04:00
```shell
2020-08-25 07:40:01 -04:00
sudo mkdir -p /usr/local/sbin
2020-06-18 10:59:51 -04:00
sudo chown $(whoami):admin /usr/local/sbin/
```
2020-08-10 19:35:31 -04:00
### Step 2: create `spoof.sh` script
2020-06-18 10:59:51 -04:00
```shell
cat < < "EOF" > /usr/local/sbin/spoof.sh
#! /bin/sh
set -e
export LC_CTYPE=C
dirname=`dirname "${BASH_SOURCE}"`
# Spoof computer name
first_name=`sed "$(jot -r 1 1 2048)q;d" $dirname/first_names.txt | sed -e 's/[^a-zA-Z]//g'`
2020-09-10 10:10:51 -04:00
model_name=`system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//'`
computer_name="$first_name’ s $model_name"
2020-06-18 10:59:51 -04:00
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"
2020-09-10 10:10:51 -04:00
printf "%s\n" "Spoofed hostname to $host_name"
2020-06-18 10:59:51 -04:00
# 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"
2020-09-10 10:10:51 -04:00
printf "%s\n" "Spoofed MAC address of en0 interface to $mac_address"
2020-06-18 10:59:51 -04:00
EOF
```
2020-08-10 19:35:31 -04:00
### Step 3: make `spoof.sh` executable
2020-06-18 10:59:51 -04:00
```shell
chmod +x /usr/local/sbin/spoof.sh
```
2020-08-10 19:35:31 -04:00
### Step 4: download [first_names.txt](first_names.txt)
2020-06-18 10:59:51 -04:00
This list includes the top 2048 most popular baby names from the [USA Social Security Administration ](https://www.ssa.gov/oact/babynames/limits.html ).
```shell
2020-07-14 16:57:34 -04:00
curl -o /usr/local/sbin/first_names.txt https://sunknudsen.com/static/media/privacy-guides/how-to-spoof-anonymize-your-mac-address-and-hostname-automatically-at-boot-on-macos/first_names.txt
2020-06-18 10:59:51 -04:00
```
2020-08-10 19:35:31 -04:00
### Step 5: download [mac_address_prefixes.txt](mac_address_prefixes.txt)
2020-06-18 10:59:51 -04:00
This list includes 768 Apple MAC address prefixes.
```shell
2020-07-14 16:57:34 -04:00
curl -o /usr/local/sbin/mac_address_prefixes.txt https://sunknudsen.com/static/media/privacy-guides/how-to-spoof-anonymize-your-mac-address-and-hostname-automatically-at-boot-on-macos/mac_address_prefixes.txt
2020-06-18 10:59:51 -04:00
```
2020-08-10 19:35:31 -04:00
### Step 6: create `local.spoof.plist` launch daemon
2020-06-18 10:59:51 -04:00
This step is responsible for running `spoof.sh` every time your Mac boots.
```shell
2020-08-25 07:40:01 -04:00
cat < < "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist
2020-06-18 10:59:51 -04:00
<?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" >
2020-08-25 07:40:01 -04:00
< dict >
< key > Label< / key >
< string > spoof< / string >
< key > ProgramArguments< / key >
< array >
< string > /usr/local/sbin/spoof.sh< / string >
< / array >
< key > RunAtLoad< / key >
< true / >
< / dict >
2020-06-18 10:59:51 -04:00
< / plist >
EOF
```
2020-08-10 19:35:31 -04:00
### Step 7: reboot and confirm hostname and MAC address have been spoofed
2020-06-18 10:59:51 -04:00
```shell
# Spoofed hostname
2020-08-25 07:40:01 -04:00
$ scutil --get HostName
Gatlins-MacBook-Pro
2020-06-18 10:59:51 -04:00
# Spoofed MAC address
2020-08-25 07:40:01 -04:00
$ ifconfig en0 | grep ether | awk '{print $2}'
20:ee:28:31:03:f6
2020-06-18 10:59:51 -04:00
# Hardware MAC address
2020-08-25 07:40:01 -04:00
$ networksetup -listallhardwareports | awk -v RS= '/en0/{print $NF}'
9c:f4:8e:d6:2b:7d
2020-06-18 10:59:51 -04:00
```
"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!
2020-08-10 19:35:31 -04:00
### Step 1: set computer name, local hostname and hostname
2020-06-18 10:59:51 -04:00
Replace `John Doe` with a value to your liking. Don’ t forget to replace empty spaces by `-` for `LocalHostName` and `HostName` .
```shell
sudo scutil --set ComputerName "John Doe"
sudo scutil --set LocalHostName "John-Doe"
sudo scutil --set HostName "John-Doe"
```
2020-08-25 07:40:01 -04:00
### Step 2: set MAC address to default value
2020-06-18 10:59:51 -04:00
2020-08-25 07:40:01 -04:00
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.
2020-06-18 10:59:51 -04:00
```shell
sudo rm /Library/LaunchDaemons/local.spoof.plist
```
2020-08-25 07:40:01 -04:00
### Step 3: delete script and datasets
2020-06-18 10:59:51 -04:00
```shell
rm /usr/local/sbin/spoof.sh
rm /usr/local/sbin/first_names.txt
rm /usr/local/sbin/mac_address_prefixes.txt
```