Change mac address with macchanger Linux command

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

Changing the MAC address with the macchanger command on Linux

Changing the MAC address with the macchanger command on Linux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software macchanger
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

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.

To install macchanger on Ubuntu, Debian, and Linux Mint:

$ sudo apt install macchanger

To install macchanger on CentOS, Fedora, AlmaLinux, and Red Hat:

$ sudo dnf install macchanger

To install macchanger on Arch Linux and Manjaro:

$ sudo pacman -S macchanger

On some systems, you may get the following prompt during installation.

Prompt asking if you want to change MAC address automatically

Prompt asking if you want to change MAC address automatically



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
Identify the name of the network interface you want to change

Identify the name of the network interface you want to change

As you can see in the screenshot above, the name of our network interface is enp0s3.

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 08:00:27:ea:82:f9.

ip a command shows the current MAC address

ip a command shows the current MAC address

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 macchanger command.

  1. Use the -r option to get a random MAC address. In addition, just specify the name of your network interface.
    $ sudo macchanger -r enp0s3
    

    The output should show your current MAC address and the new one that has been assigned from macchanger.

  2. To verify the change, try running the ip a command again and you should see the new MAC address listed.
    $ ip a
    


  3. New MAC address configured for the network interface

    New MAC address configured for the network interface

  4. If you need to use a specific MAC address, you can do that with the -m option and the following command syntax.
    $ sudo macchanger -m b2:aa:0e:56:ed:f7 enp0s3
    
  5. Changing the MAC address to a specific value

    Changing the MAC address to a specific value

  6. 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 macchanger to 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 -l option.
    $ macchanger -l
    

Closing Thoughts

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.



Comments and Discussions
Linux Forum