How to Change MAC Address in Linux

When your device gets connected to the wifi network, its mac address gets shared with the router, which can be easily accessed from the router admin page, or someone from the network can look out for your device.

MAC (Media Access Control Address) address is one of the most physical identifiers assigned to your network interface controller. Every device has its own unique mac address, which is set at manufacturing but can be changed using a few tools.

Sometimes you want to change this mac (also known as a physical address) for various reasons. Like, if you are connected to an airport or railway wifi, they have a limit cap. When your data usage hits that cap, you may face slow internet speed. To avoid that, you can spoof your system’s mac address and trick them into believing it’s a different device.

One more example is you using someone’s wifi, and then suddenly you cannot connect to that wifi. There is a chance that they may have blocked you on their network.

At this moment, changing your mac address can help you avoid a router firewall and access the internet.

Let’s see how we can change or spoof our mac address using one of the simplest and best freeware utilities along with iproute in the Linux Operating System.

Find your Physical MAC Address

One of the preliminary steps before changing the mac address is to find the network interface card (NIC) name of the network adapter for which you want to change the mac address. 

$ ip link show

The above code lists all of the network interfaces attached to your laptop or desktop system.

List of all network interface
List of all network interface

In my case, I am connected to my wifi using the wlxd46e0e157248 network adapter. You can see the 48 bit mac address of that adapter after link/ether d4:6e:0e:15:74:42.

Don’t forget to note your original mac address and store it in a secure and safe place in case you want to revert to your original.

Use the Macchanger Utility to change the MAC Address

Macchanger is a simple freeware utility to view, modify, and replace the mac address of your network interface. It is available in almost all popular Linux distribution repositories, so you just need to execute the following command as per your respective distributions.

Installation

on Debian/Ubuntu/PopOS/Linux Mint/Kali Linux/Parrot

$ sudo apt install macchanger

on Fedora/CentOS/RHEL/Alma/Rocky Linux

$ sudo dnf install macchanger

on Arch/Manjaro/EndeavourOS

$ sudo pacman -S macchanger

Note that while installing macchanger, it will prompt to ask whether to assign a new mac address automatically whenever the network is brought up or down. I recommend not using this in several cases. If you are required not to show your real mac address, go with it.

macchanger

Network Interface Down

Once you have installed the macchanger utility on your Linux distribution, you need to perform one more step which will allow you to change your mac address without any errors, and it will prevent you from following something like “[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy”.

I do believe you are aware of the nic card name from the above command, so you can execute the below command to “down your network interface”.

$ sudo ip link set wlxd46e0e157248 down

After turning off your network interface, you will not be able to access the internet, which is a good sign that we are moving toward the next step.

Changing to Random MAC Address

I hope you remember the network interface name we noted in step one. Once we get that, we can easily assign a random mac address to that network interface using the below command syntax.

$ sudo macchanger -r [network-interface] 

Let’s say you want to change the mac address of your wireless network interface, whose name is “wlxd46e0e157248”, to a random mac address. Then you need to invoke the below command, which will replace the current mac address with a different mac address.

$ sudo macchanger -r wlxd46e0e157248

The output of the above command.

Random MAC address assigned
Random MAC address is assigned 

After executing the above command, you will find the output, which will confirm the changes with the following details: your current MAC, permanent MAC, and newly random MAC address.

Even you can verify the same thing using the ip link show command.

$ ip link show

If you are satisfied with a random MAC address, then you can turn up your network interface to access the internet.

Changing to a Custom MAC Address

Instead of setting a random mac address, you can specify a mac address that is on your mind. To implement that first, you need to disable the interface if you have enabled it, otherwise you simply follow the below command syntax to assign a custom mac address. 

$ sudo macchanger --mac=XX:XX:XX:XX:XX:XX [network-interface]

Replace XX:XX:XX:XX:XX:XX with your new custom mac address.

Let’s say you want to change the MAC address of the network card named “wlxd46e0e157248“, then execute the below code, which will set the new mac address for the corresponding nic. 

$ sudo macchanger --mac=x4:ip:12:0c:37:0c wlxd46e0e157248

Revert Back to the Original MAC Address

Going back to the original mac address is pretty easy. There are two steps to follow. First, if you noted your actual mac address, you can set it as a custom mac address. Otherwise, go with the below command, which automatically changes your new generated mac address into your original OEM given address.

$ macchanger -p wlxd46e0e157248

Use the ip command to set a temporary MAC address

Alternatively, you can use the same ip command, which is the successor of the ifconfig command, and it is also one of the simpler ways to assign a temporary mac address to your device.

One of the advantages over macchanger is that you can set a temporary mac address, which will be automatically reverted once you restart your system.

List network interface

Before moving ahead, you should first know your network interface name. If you are aware your network interface name, then you can skip this section and read the next step. 

For those who are not aware of the interface name, execute the below code which will show the network card name which is assigned by the kernel at startup or later in the case of an external wifi adapter.

$ ip link

The behaviour of the above command:

List of all network interfaces 

From the list of network interfaces, I have selected my external Wifi adapter, which starts with wlxd46e0e157248. Really, it’s a pretty odd name. If you read the above output, you can even find out your current mac address. In my case, it’s d4:6e:0e:15:74:42.

Interface down

Once you decide the network interface name of which you want to change the mac address, then execute the below command to down the respective network interface device. Otherwise, you won’t be able to change the mac address.

$ sudo ip link set wlxd46e0e157248 down

Change MAC address

Lastly, you need to execute the below code, which will change your original mac address to a fake mac address. Although the newly created mac address will get reverted to the original mac address once you restart your system, you should still keep a note of your original mac address to revert to the original mac address if anything gets wrong.

$ sudo ip link set wlxd46e0e157248 4c:aa:69:cv:43:ax

Once the command is executed successfully, you will not receive any output on your terminal screen, so to verify whether our changes went successfully or not, run the below code:

$ ip link
After mac address change
After the mac address change

After all that you need to do is “up your system network interface” to access the internet connection, which we have down in earlier step.

$ sudo ip link set wlxd46e0e157248 up

Now your network device has a  different mac address than what you have got from the hardware vendor. 

If you are pondering, how do I revert to the original mac address without rebooting? Then simply follow the same steps and provide the original mac address if you have noted it down, or else use the ip link command to get your original mac address, and then change it back.

Final Thoughts

Changing or spoofing MAC addresses has been a lifesaver many times. But it is strictly prohibited to use it for non-ethical activities like card*** and hacking.

Stick with us to learn more useful technology and Linux tips.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Josef V.
Josef V.
1 year ago

Isn’t to prevent tracking the #1 reason for changing a MAC address?

Maybe mention how many Linux distributions based on Ubuntu now provide for 4 settings of MAC address changing via the UI. Persistent . Easy.