A Media Access Control (MAC) address is a unique number that gets assigned to every network interface, including Ethernet and wireless. It's used by many system programs and protocols in order to identify a network interface. One of the most common examples would be in the case of DHCP, where a router assigns an IP address to a network interface automatically. The router will know which device it has assigned an IP address to by referring to the MAC address.
Unlike an IP address, which is temporary and can be changed easily, MAC addresses are hardcoded into a network interface from the manufacturer. However, it's still possible to change or "spoof" a MAC address temporarily. On Linux systems, one of the easiest ways to do this is with the macchanger command line program. There are both legitimate and shady reasons for why a Linux user may find the need to change a MAC address.
In this guide, we'll show how to install the macchanger program on major Linux distros and then use the macchanger command to change the MAC address of a network interface either to a random value or some specific number. Follow the examples below to learn how.In this tutorial you will learn:
- How to install macchanger on major Linux distros
- How to identify current MAC address and network interface
- How to change an interface's MAC address
- How to change interface to a specific MAC address
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Install macchanger on major Linux distros
Before diving into the usage instructions for macchanger, you'll need to have it installed on your system. Most likely, it won't be installed by default since it's a rather niche application. You can use your Linux distro's built-in package manager to install macchanger. Use the appropriate command below to install it.
$ sudo apt install macchanger
$ sudo dnf install macchanger
$ sudo pacman -S macchanger
On some systems, you may get the following prompt during installation.
In most cases, you'll probably want to select
no. Otherwise, your network interfaces will be given a new MAC address every time they come online or you reboot the system. In specific scenarios, this could be a good thing, but in most cases, probably not. We'll still be able to assign a new MAC address whenever we want to.
Once it installs, the macchanger command will be available and you can follow along with the examples below.
Use macchanger to change an interface's MAC address
Before we start using the
macchanger command, you'll need to know the name of the network interface that you want to work with. You can execute the
ip a command to see a list of all the available network interfaces on your system. In most cases this will include a wired, wireless, and loopback interface.
$ ip a
As you can see in the screenshot above, the name of our network interface is
The second line of the output shows our current MAC address, which we've highlighted in the screenshot below. In our case, the MAC address is
Now we can begin to change the MAC address. Follow along with the step by step instructions below to see how. Note that you will need root permissions in order to execute the
- Use the
-roption to get a random MAC address. In addition, just specify the name of your network interface.
$ sudo macchanger -r enp0s3The output should show your current MAC address and the new one that has been assigned from
- To verify the change, try running the
ip acommand again and you should see the new MAC address listed.
$ ip a
- If you need to use a specific MAC address, you can do that with the
-moption and the following command syntax.
$ sudo macchanger -m b2:aa:0e:56:ed:f7 enp0s3
- Various vendors have different MAC address prefixes. Therefore, you can usually identify the manufacturer of a network device by looking at the first few bits of the MAC address. This means we can use
macchangerto make our device look as if it belongs to a certain manufacturer. To see a list of known MAC addresses and their corresponding vendors, use the
$ macchanger -l
In this guide, we saw how to change the MAC address of a network interface on Linux. This is done through the macchanger utility, which can be easily installed from the default repos of most major Linux distributions. We also learned a few different options to use with the command, in case you'd like to have a random MAC address, a specific one, or one from a particular vendor.