$$ %---- MACROS FOR SETS ----% \newcommand{\znz}[1]{\mathbb{Z} / #1 \mathbb{Z}} \newcommand{\twoheadrightarrowtail}{\mapsto\mathrel{\mspace{-15mu}}\rightarrow} % popular set names \newcommand{\N}{\mathbb{N}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\Q}{\mathbb{Q}} \newcommand{\R}{\mathbb{R}} \newcommand{\C}{\mathbb{C}} \newcommand{\I}{\mathbb{I}} % popular vector space notation \newcommand{\V}{\mathbb{V}} \newcommand{\W}{\mathbb{W}} \newcommand{\B}{\mathbb{B}} \newcommand{\D}{\mathbb{D}} %---- MACROS FOR FUNCTIONS ----% % linear algebra \newcommand{\T}{\mathrm{T}} \renewcommand{\ker}{\mathrm{ker}} \newcommand{\range}{\mathrm{range}} \renewcommand{\span}{\mathrm{span}} \newcommand{\rref}{\mathrm{rref}} \renewcommand{\dim}{\mathrm{dim}} \newcommand{\col}{\mathrm{col}} \newcommand{\nullspace}{\mathrm{null}} \newcommand{\row}{\mathrm{row}} \newcommand{\rank}{\mathrm{rank}} \newcommand{\nullity}{\mathrm{nullity}} \renewcommand{\det}{\mathrm{det}} \newcommand{\proj}{\mathrm{proj}} \renewcommand{\H}{\mathrm{H}} \newcommand{\trace}{\mathrm{trace}} \newcommand{\diag}{\mathrm{diag}} \newcommand{\card}{\mathrm{card}} \newcommand\norm[1]{\left\lVert#1\right\rVert} % differential equations \newcommand{\laplace}[1]{\mathcal{L}\{#1\}} \newcommand{\F}{\mathrm{F}} % misc \newcommand{\sign}{\mathrm{sign}} \newcommand{\softmax}{\mathrm{softmax}} \renewcommand{\th}{\mathrm{th}} \newcommand{\adj}{\mathrm{adj}} \newcommand{\hyp}{\mathrm{hyp}} \renewcommand{\max}{\mathrm{max}} \renewcommand{\min}{\mathrm{min}} \newcommand{\where}{\mathrm{\ where\ }} \newcommand{\abs}[1]{\vert #1 \vert} \newcommand{\bigabs}[1]{\big\vert #1 \big\vert} \newcommand{\biggerabs}[1]{\Bigg\vert #1 \Bigg\vert} \newcommand{\equivalent}{\equiv} \newcommand{\cross}{\times} % statistics \newcommand{\cov}{\mathrm{cov}} \newcommand{\var}{\mathrm{var}} \newcommand{\bias}{\mathrm{bias}} \newcommand{\E}{\mathrm{E}} \newcommand{\prob}{\mathrm{prob}} \newcommand{\unif}{\mathrm{unif}} \newcommand{\invNorm}{\mathrm{invNorm}} \newcommand{\invT}{\mathrm{invT}} \newcommand{\P}{\text{P}} \newcommand{\pmf}{\text{pmf}} \newcommand{\pdf}{\text{pdf}} % real analysis \renewcommand{\sup}{\mathrm{sup}} \renewcommand{\inf}{\mathrm{inf}} %---- MACROS FOR ALIASES AND REFORMATTING ----% % logic \newcommand{\forevery}{\ \forall\ } \newcommand{\OR}{\lor} \newcommand{\AND}{\land} \newcommand{\then}{\implies} % set theory \newcommand{\impropersubset}{\subseteq} \newcommand{\notimpropersubset}{\nsubseteq} \newcommand{\propersubset}{\subset} \newcommand{\notpropersubset}{\not\subset} \newcommand{\union}{\cup} \newcommand{\Union}[2]{\bigcup\limits_{#1}^{#2}} \newcommand{\intersect}{\cap} \newcommand{\Intersect}[2]{\bigcap\limits_{#1}^{#2}} \newcommand{\intersection}[2]{\bigcap\limits_{#1}^{#2}} \newcommand{\Intersection}[2]{\bigcap\limits_{#1}^{#2}} \newcommand{\closure}{\overline} \newcommand{\compose}{\circ} % linear algebra \newcommand{\subspace}{\le} \newcommand{\angles}[1]{\langle #1 \rangle} \newcommand{\identity}{\mathbb{1}} \newcommand{\orthogonal}{\perp} \renewcommand{\parallel}[1]{#1^{||}} % calculus \newcommand{\integral}[2]{\int\limits_{#1}^{#2}} \newcommand{\limit}[1]{\lim\limits_{#1}} \newcommand{\approaches}{\rightarrow} \renewcommand{\to}{\rightarrow} \newcommand{\convergesto}{\rightarrow} % algebra \newcommand{\summation}[2]{\sum\nolimits_{#1}^{#2}} \newcommand{\product}[2]{\prod\limits_{#1}^{#2}} \newcommand{\by}{\times} \newcommand{\integral}[2]{\int_{#1}^{#2}} \newcommand{\ln}{\text{ln}} % exists commands \newcommand{\notexist}{\nexists\ } \newcommand{\existsatleastone}{\exists\ } \newcommand{\existsonlyone}{\exists!} \newcommand{\existsunique}{\exists!} \let\oldexists\exists \renewcommand{\exists}{\ \oldexists\ } % statistics \newcommand{\distributed}{\sim} \newcommand{\onetoonecorresp}{\sim} \newcommand{\independent}{\perp\!\!\!\perp} \newcommand{\conditionedon}{\ |\ } \newcommand{\given}{\ |\ } \newcommand{\notg}{\ngtr} \newcommand{\yhat}{\hat{y}} \newcommand{\betahat}{\hat{\beta}} \newcommand{\sigmahat}{\hat{\sigma}} \newcommand{\muhat}{\hat{\mu}} \newcommand{\transmatrix}{\mathrm{P}} \renewcommand{\choose}{\binom} % misc \newcommand{\infinity}{\infty} \renewcommand{\bold}{\textbf} \newcommand{\italics}{\textit} \newcommand{\step}{\text{step}} $$

How to Spoof Your MAC Address and Host Name on Ubuntu

Guy Fawkes mask hiding in trees

Photo by Javardh on Unsplash

If you value privacy and don’t want networks to track your computer, a good first step is to spoof your computer’s MAC address and host name.

You MAC address is the hardware identifier assigned to your network card. When you connect to a network, a router gives your computer an IP address and stores both your MAC and IP address in a table.

This happens with any network you join and your MAC address never changes. This means that there’s a record of all the places you’ve been to over the years. In short, networks are tracking you.

Along with your MAC address, your computer’s name or “hostname” is also visbile on a network depending upon which services you use. On MacBooks, your hostname could be something like “Bobby’s MacBook Pro”. But it’s possible you’re not comforable with broadcasting your name over a network.

To protect yourself, you want to do two things when connecting a computer to a wireless network:

  1. Use a fake MAC address by randomly choosing a MAC address to assign to the wireless network card.
  2. Use a fake hostname by randomly choosing a name from the first-names.txt file and assigning it as the new hostname.

The code would look like this:

#!/bin/sh

set -e

basedir=$(dirname "$0")

# Get wireless adapter name
wireless_name=$(ls /sys/class/net | grep w)
# Turn off wireless
sudo ifconfig $wireless_name down
# Change MAC address to random MAC address
sudo macchanger -r $wireless_name
# Turn on wireless again
sudo ifconfig $wireless_name up

# Get random name from first-names.txt file
first_name=$(shuf -n 1 $basedir/first-names.txt | sed -e 's/[^a-z]//g')

sudo hostnamectl set-hostname $first_name

Now all you need to do is execute this code any time your computer joins a wireless network. In Ubuntu, this means:

  1. Copying your script and putting it in /etc/network/if-up.d/.
  2. Ensuring your script name doesn’t have a .sh at the end.
  3. Making the script executable (i.e. chmod +x my-script).

Then the script might look like:

#!/bin/sh

set -e

basedir=$(dirname "$0")

# Get wireless adapter name
wireless_name=$(ls /sys/class/net | grep w)

# If the interface is wireless (and not ethernet)
if [ "$IFACE" = $wireless_name ]; then
  # Turn off wireless
  sudo ifconfig $wireless_name down
  # Change MAC address to random MAC address
  sudo macchanger -r $wireless_name
  # Turn on wireless again
  sudo ifconfig $wireless_name up
  
  # Get random name from first-names.txt file
  first_name=$(shuf -n 1 $basedir/first-names.txt | sed -e 's/[^a-z]//g')
  
  sudo hostnamectl set-hostname $first_name
fi

That’s it! You can verify a change in hostname by running hostname in the terminal and verify you’ve got a new MAC address by running ip link show | awk '{print$2}' | tail -1.

If you have a MacBook instead, you can achieve what you did in this article by following Sun Knudsen’s steps for macOS.

comments powered by Disqus