Change MAC Address on Linux

Hello Guys, I’m Yasiru Navoda Jayasekara. Today I’m going to show you how to change MAC Address on Linux. In this case, I used Kali Linux 2021.3

Introduction

Our network card includes at least two addresses or identifiers. Those are IP Addresses and MAC Addresses. The MAC Address, which is unique to each device and serves as the hardware address. Changing our mac address may be beneficial in preventing logs with our true address from being left on another computer or router. Changing the mac address may be used to clone other mac addresses by causing them to disconnect from a network and reconnect again, allowing the password to be sniffed when the device is reinserted.

source***

Now I am going to show steps for changing the MAC address with 2 methods.

Method 1 ( using Linux terminal )

step 1:First of all, need to get our original mac address. To do so, use this command in the terminal.

ifconfig

eth0 is your network interface card and you can also view the mac address under ether. Mac addresses have 12 digits, 6 fields of 2 characters, and letters separated by “:” like XX:XX:XX:XX:XX:XX.

step 2: Before changing the mac address, you must shut down the presently active network interface. To do so, enter the following command and enter the password.

sudo ifconfig eth0 down

Check your internet connection was disconnected.

step 3: Now we can go to the command to change the mac address. To do so, use the following command.

sudo ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX

Then in step 2 the disconnected connection must be re-up.

sudo ifconfig eth0 up

Finally, you can run the ifconfig command to see if the connection is successful and if the mac address has changed.

There are several issues that arise here.

1: Frequent entry of super-user account password.

solution: Change normal-user to Super-User(root).To do so, run the sudo su command and enter the password.

The password is not required when performing the above steps from the super-user.

2: Obtain the default mac address again after changing the mac address.

solution 1: restart the OS.😜

solution 2: reset network interface. To do this, use the following command.

sudo ifconfig eth0 hw ether $(ethtool -P eth0 | awk '{print $3}')

Method 2 ( using Python Script)

pre-requirements: Install python3 & pycharm IDE.

Open Pycharm IDE > Create New Project > Create New Python file

Then write the following code in the created python file.

#!/user/bin/env/pythonimport subprocessnew_mac = input("Enter your mac address : ")print("********************************")
print("[+++] changing your MAC address to " + new_mac + " [+++]")
print("********************************")
subprocess.call("ifconfig eth0 down", shell=True)
subprocess.call("ifconfig eth0 hw ether " + new_mac, shell=True)
subprocess.call("ifconfig eth0 up", shell=True)

Then save the code, open the terminal from the saved location and execute the python file. (Change normal-user to Super-User(root)).

python code

terminal

Note: The above commands may vary depending on the OS version.

This is the end of this story. Hope you learned something. Good Bye!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store