Change Your MAC Address
- What is a MAC address?
- Why randomize your MAC address?
- What limitations will this impose?
- Setup automatic random MAC address creation in Linux using Network Manager
This guide will show you how to generate a new MAC address every time you connect to a computer network.
A MAC (Media Access Control) address is a unique address present in all networking hardware. It identifies the specific network card (and thus, if you don’t change network cards very often, your computer) you use to connect to a computer network. It’s similar to an IP address in its ability to uniquely identify you, but more directly tied to the hardware you’re using.
Since it is a unique identifier, it can be used to track you while on the internet. This is especially relevant at open access points, such as when using free networks offered by major coffee chains or fast food dispensaries. If you connect to free public networks, it’s strongly recommended to use generated MAC address as described below because it’s trivial and likely being done to build entire profiles on you based around your MAC address.
Some routers identify you by your MAC address, giving you a specific IP as a result or allowing you to use their services. Any service that is linked to a specific network adapter may stop functioning if you use this method. If you don’t know what that means, however, it’s very likely that it’s not a problem. More likely is the necessity to click through any portals that come up automatically when first signing onto a public network which prompts the user with something before providing internet service. Examples of this typically come in the form of free wireless access points provided by corporate entities—you’ll probably have to ‘agree’ to ‘terms of service’ again every time you connect to free corporate wireless access points.
To find your current MAC address look into `/sys/class/dev` e.g. by running `ls /sys/class/dev` or open Network Manager. `lo` usually indicates localhost, LAN connections usually start with `e`. `ip link` provides some more details.
Ubuntu 10.04 (and as of September 1, 2010 and the near future, all distributions using Network Manager) ships with a version of Network Manager that does not support “pre-up” scripts for network connections—this means that it is unable to run scripts before connecting to a network. This feature would easily enable one to use a script that changes the MAC address on every connection. Due to this limitation, this guide specifically generates a random MAC address every time the Network Manager service starts, and then generates a new one every time you disconnect from the network.
- Open a terminal and run:
sudo apt-get install macchanger
- It’s suggested to take note of your current MAC address at this point, to verify that it is being changed by your scripts later on. To do this for a wired (ethernet) connection, type:
to do the same for a wireless adapter, type:
The output will look something like this:
Current MAC: 00:0c:1d:47:a4:0c (Mettler & Fuchs Ag)
00:0c:1d:47:a4:0c is the MAC address in this instance, always in the form of XX:XX:XX:XX:XX:XX. The text in the parentheses will vary.
- Create the file /etc/init/macchanger.conf. This can be done by typing:
sudo nano /etc/init/macchanger.conf
- Paste the following lines into it and save the file (Ctrl+X will save and close in nano):
# macchanger - set MAC addresses # # Set the MAC addresses for the network interfaces. description "change mac addresses" start on starting network-manager pre-start script /usr/bin/macchanger -A wlan0 /usr/bin/macchanger -A eth0 /usr/bin/macchanger -A wmaster0 /usr/bin/macchanger -A pan0 #/usr/bin/logger wlan0 `/usr/bin/macchanger -s wlan0` #/usr/bin/logger eth0 `/usr/bin/macchanger -s eth0` end script
This script runs after the network manager service starts through the Ubuntu Upstart daemon system then, using the -A switch, creates a random vendor-identified MAC address. The program macchanger can generate various kinds of addresses—this method may look strange to active network monitoring, but passive network monitoring and background tracking will likely not notice. This method should work best for most people.
- Create the file /etc/network/if-post-down.d/random-mac and paste the following lines into it:
#!/bin/sh MACCHANGER=/usr/bin/macchanger [ "$IFACE" != "lo" ] || exit 0 # Bring down interface (for wireless cards that are up to scan for networks), change MAC address to a random vendor address, bring up the interface /sbin/ifconfig "$IFACE" down macchanger -A "$IFACE"
This script changes the MAC address again when the network is disconnected. It’s possible if the network is never properly brought down and one never reboots that one can use the same address more than once.
- Make the random-mac script executable by typing:
sudo chmod +x /etc/network/if-post-down.d/random-mac
- Restart Network Manager to take effect:
sudo service network-manager restart
Your computer will now automatically create (without your intervention or notification) a new random MAC address for every physical network adapter you have (wired and WIFI) and reduce your trackability on public networks!
This tactic can easily be adapted to different linux/BSD setups and possibly OS X and Windows—if you create a new implementation, add it here!