Linux Commands

How to Find and Change the MAC Address on Linux

This tutorial explains how to find and change the network card MAC address on Linux.

Network cards have a minimum of two addresses to be identified, at least one IP address (You can assign more than one), and a physical address named MAC address. Like the IP address, the MAC address is unique for each device. While the IP is the software address, the MAC is the hardware or physical address. Contrary to the IP, the MAC is permanent and assigned from the factory.

Yet, while the MAC address is permanent from the hardware side, there are some workarounds to change it before the network or other devices. This is useful, for example, to be able to connect routers or networks allowing specific MAC addresses, or to avoid leaving traces. Another usage example would be cloning a MAC address of another device forcing it to disconnect from a network and to connect again, useful to sniff a password when the device reconnects.

After reading this article, you will know how to change your MAC address both manually and automatically, with a specific MAC address or with a random one.

All steps described in this tutorial include screenshots, making it easy for any Linux user to follow them.

How to Manually Find and Change the MAC Address in Linux

To check your current MAC address, run the command shown in the screenshot below.

ip address show

In the screenshot above, you can see two network cards, the ethernet card named enp2s0 and the wireless card named wlp3s0. The MAC addresses contain 12 digits, 6 fields of 2 characters and letters separated by colons “:” like XX:XX:XX:XX:XX:XX. The ethernet card’s MAC address is d0:17:c2:12:3c:cd while the wlp3s0 wi-fi card MAC address is a2:58:a6:6a:29:04.

The first 6 characters and numbers identify the device manufacturer, in my case d0:17:c2, which belongs to ASUS. The last 12 digits are the ID number for the hardware and it is unique.

The MAC address cannot be changed while the network card is up. Therefore, edit the MAC before you need to set the network card down. You can do it using the ip command as shown in the example below, where <Device> must be replaced with your network device.

sudo ip link set dev <Device> down

Now, you can assign a new MAC address to your device by executing the command below, where <Device> must be replaced with your network device, and <New MAC address> must be replaced with the new MAC address you want to assign to your device.

sudo ip link set dev <Device> address <New mac address>

Finally, set your network card up again by running the following command, where <Device> must be replaced with your network card.

sudo ip link set dev <Device> up

As you can see in the screenshot below, the MAC address was changed successfully from the one shown in the first screenshot (d0:17:c2:12:3c:cd) to 00:00:00:00:00:01.

The issue with the manual method is after rebooting your device, the original MAC address will be restored.

Change the MAC Address Automatically or Randomly

This section explains how to change the MAC address automatically, or how to assign a random MAC address.

For this purpose, you will need to install the program Macchanger. To install it on Debian and its based Linux distributions, execute the command below.

sudo apt install macchanger

During the installation process, you will be asked if you want macchanger to change your MAC address automatically every time your network card connects to the network. Select the option you want and press ENTER.

Once macchanger is installed, to assign your network card a random MAC, execute the following command, where <Device> is your network device.

sudo macchanger -r <Device>

The -r (Random) parameter tells macchanger to generate a random MAC address.

Note: In case you get an error when executing the previous command, first disable your network device by running sudo ip link set dev <Device> down and then execute the command again, and run sudo ip link set dev <Device> up . This should be unnecessary, but use it in case of errors.

To assign a specific MAC address using macchanger, instead of using the -r parameter, use -m as shown in the example below, where <New Mac Address> is the new MAC you want to assign, and <Device> the network card.

sudo macchanger -m <New Mac Address> <Device>

Find and Change the MAC Address Using the Old ifconfig Command

Old Linux users know the ifconfig command, the predecessor of the ip command used in the first section of this tutorial explaining how to change the MAC address in Linux.

If you are using a very old Linux distribution or you have installed the net-tools package, you also can use the ifconfig command to change your MAC address.

The process is the same as with the ip command. First turn your network card down.

sudo ifconfig <Device> down

Then, assign the new MAC address by running the following command, where <Device> is your network card and <New Mac Address> the new MAC.

sudo ifconfig <Device> hw ether <New Mac Address>

Then, set your network card up again.

sudo ifconfig <Device> up

As you can see in the screenshot below, the MAC address was changed successfully.

That’s all. Three formidable methods to change your MAC in Linux.


As you can see, changing your MAC address may have advanced purposes, but the task itself is pretty easy and can be executed by any Linux user. Linux offers different methods to change your MAC, the three most popular ones are explained above in this article. Always when changing your MAC, make sure you are not filtering other addresses, or you may get disconnected until reestablishing the allowed address. Also remember the last technique (ifconfig) will only work on old Linux distributions or systems with the net-tools package installed. Another important point to remember is that except for the macchanger method (If you configured it to work automatically), both ip and ifconfig original addresses will be restored after reboot.

Thank you for reading this article showing how to change the MAC address in Linux. I hope it was useful for you. Keep following us for more Linux professional tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.